BIT can answer: "what is the -th smallest element currently in the structure?"
Approach: binary search on the prefix sum.
def kthSmallest(k):
pos = 0
for i in range(LOG, -1, -1): # LOG = log2(n)
if pos + (1 << i) <= n and tree[pos + (1 << i)] < k:
pos += (1 << i)
k -= tree[pos]
return pos + 1
This descends the BIT structure bit by bit, similar to binary lifting.
Use case: maintain a dynamic multiset, supporting insert, delete, and k-th element queries in each.