BIT can implement a dynamic multiset supporting:
- : add element
- : remove one occurrence of
- : count elements
- : find -th smallest element
Implementation:
def insert(x):
update(x, +1)
def delete(x):
update(x, -1)
def countLess(x):
return query(x - 1)
def kth(k):
return findFirst(k)
With coordinate compression, this handles any value range in per operation.