driver code
int main ( ) { int a [ ] = { 1 , 1 , 2 , 1 , 3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; Query queries [ 3 ] ; queries [ 0 ] . l = 0 ; queries [ 0 ] . r = 4 ; queries [ 0 ] . idx = 0 ; queries [ 1 ] . l = 1 ; queries [ 1 ] . r = 3 ; queries [ 1 ] . idx = 1 ; queries [ 2 ] . l = 2 ; queries [ 2 ] . r = 4 ; queries [ 2 ] . idx = 2 ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; sort ( queries , queries + q , cmp ) ; answeringQueries ( a , n , queries , q ) ; return 0 ; }