#P5076. 【深基16.例7】普通二叉树(简化版)
【深基16.例7】普通二叉树(简化版)
Description
You need to implement a data structure to maintain a set of numbers (all numbers have absolute value within ). The set is initially empty. You need to support the following operations, and the number of operations does not exceed :
- Define the rank of a number as the number of elements in the set that are less than , plus . Query the rank of . Note that may not be in the set.
- Query the number whose rank is (). It is guaranteed that the set contains at least numbers.
- Find the predecessor of (the predecessor is defined as the largest number that is less than ). If it does not exist, output .
- Find the successor of (the successor is defined as the smallest number that is greater than ). If it does not exist, output .
- Insert a number . The testdata guarantees that before insertion, is not in the set.
It is guaranteed that when performing operations , , and , the set contains at least one element.
Input Format
The first line contains an integer , indicating the number of operations.
In the next lines, each line contains two integers , representing the operation index and the parameter .
Output Format
Output several lines. For operations , , , and , output one integer representing the result of the operation.
7
5 1
5 3
5 5
1 3
2 2
3 3
4 3
2
3
1
5
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号