Driver code
int main ( ) { int a [ ] = { 1 , 1 , 5 , 4 , 5 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; Query q [ ] = { { 0 , 2 , 2 } , { 1 , 4 , 1 } , { 2 , 4 , 5 } } ; int m = sizeof ( q ) / sizeof ( q [ 0 ] ) ; 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 ) {