Driver code
public static void main ( String args [ ] ) { int a [ ] = { 1 , 1 , 5 , 4 , 5 } ; int n = a . length ; Query q [ ] = { new Query ( 0 , 2 , 2 ) , new Query ( 1 , 4 , 1 ) , new Query ( 2 , 4 , 5 ) } ; int m = q . length ; initialize ( a , n , q , m ) ; for ( int i = 0 ; i < m ; i ++ ) { int flag = 0 ; int l = q [ i ] . L , r = q [ i ] . R , x = q [ i ] . X ; int p = r ; while ( p >= l ) {