Ezvor

3935. Power Update After K-th Largest Insertion I

MediumArray Preparing judge… LeetCode
ArrayHash TableMathSegment TreeSortingHeap (Priority Queue)

Hints

Hint 1
Keep the largest k elements separately. The answer is the smallest among them.
Hint 2
After inserting a value, rebalance the two sets/heaps so the “top k” side has exactly k elements. Since abs(ki - ki-1) < 10, only a few elements move each query.
Hint 3
Update p with fast modular exponentiation.