For each query calculate maxx for the answer and store it in ans array .
for i in range ( q + 1 ) : NEW_LINE INDENT while ( arr [ curr ] . val <= queries [ i ] . x and curr < n ) : NEW_LINE INDENT update ( Fenwick , arr [ curr ] . index + 1 , 1 , n ) NEW_LINE curr += 1 NEW_LINE DEDENT DEDENT