#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 10910^9). The set is initially empty. You need to support the following operations, and the number of operations qq does not exceed 10410^4:

  1. Define the rank of a number xx as the number of elements in the set that are less than xx, plus 11. Query the rank of xx. Note that xx may not be in the set.
  2. Query the number whose rank is xx (x1x \ge 1). It is guaranteed that the set contains at least xx numbers.
  3. Find the predecessor of xx (the predecessor is defined as the largest number that is less than xx). If it does not exist, output 2147483647-2147483647.
  4. Find the successor of xx (the successor is defined as the smallest number that is greater than xx). If it does not exist, output 21474836472147483647.
  5. Insert a number xx. The testdata guarantees that before insertion, xx is not in the set.

It is guaranteed that when performing operations 11, 33, and 44, the set contains at least one element.

Input Format

The first line contains an integer qq, indicating the number of operations.

In the next qq lines, each line contains two integers op,xop, x, representing the operation index and the parameter xx.

Output Format

Output several lines. For operations 11, 22, 33, and 44, 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