#P3369. 【模板】普通平衡树
【模板】普通平衡树
Description
You need to dynamically maintain a multiset and support the following operations:
- Insert a number into .
- Delete a number from (if there are multiple equal numbers, delete only one).
- Query how many numbers in are less than , and then add one to the result (i.e., the rank of ).
- Query the number whose rank is when is sorted in ascending order.
- Query the predecessor of in (the predecessor is defined as the maximum number that is less than ).
- Query the successor of in (the successor is defined as the minimum number that is greater than ).
For operations 3, 5, and 6, it is not guaranteed that exists in the current multiset.
For operations 5 and 6, the answer is guaranteed to exist.
Input Format
The first line contains , the number of operations. Each of the next lines contains two integers and , where denotes the operation index ().
Output Format
For operations 3, 4, 5, and 6, output one integer per line, the corresponding answer.
10
1 106465
4 1
1 317721
1 460929
1 644985
1 84185
1 89851
6 81968
1 492737
5 493598
106465
84185
492737
Hint
Constraints
For of the testdata, , .
Source: Tyvj1728, originally titled: Ordinary Balanced Tree.
Special thanks!
Translated by ChatGPT 5
京公网安备 11011102002149号