Function to perform the queries
static void performQueries ( int L [ ] , int R [ ] , int K [ ] , int n , int q , Vector < Integer > tree [ ] ) { for ( int i = 0 ; i < q ; i ++ ) { System . out . println ( query ( tree , 1 , 0 , n - 1 , L [ i ] - 1 , R [ i ] - 1 , K [ i ] ) ) ; } } static int lowerBound ( Vector < Integer > array , int length , int value ) { int low = 0 ; int high = length ; while ( low < high ) { final int mid = ( low + high ) / 2 ; if ( value <= array . elementAt ( mid ) ) { high = mid ; } else { low = mid + 1 ; } } return low ; }