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