Ordered multiset
Your task
Design an ordered multiset supporting ['add', x], ['remove', x] (remove one occurrence; no-op if absent), and ['rank', x] which returns the number of stored elements strictly less than x. Keep the structure sorted so each query is logarithmic in lookup. Given an op list, return the list of results for each 'rank'.
Examples
ordered_multiset(ops: list[list]) -> list[int]Example 1
Input
ordered_multiset([["add", 5], ["add", 3], ["add", 8], ["rank", 5], ["add", 5], ["rank", 5], ["rank", 9]])Output
[1, 1, 4]