Sort array and queries for fenwick updates
arr [ : n + 1 ] . sort ( key = lambda x : x . val ) NEW_LINE queries [ : q + 1 ] . sort ( key = lambda val : val . x ) NEW_LINE curr = 0 NEW_LINE ans = [ 0 for _ in range ( q + 1 ) ] NEW_LINE