print answer to every query using binary search
let longest = upperBound ( b , 0 , n , k ) ; document . write ( " " + ( i + 1 ) + " " + longest + " " ) ; } } function upperBound ( a , low , high , element ) { while ( low < high ) { let middle = low + parseInt ( ( high - low ) / 2 , 10 ) ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; }