#P5076. Order Statistic Set Operations

    ID: 18314 Type: Default 1000ms 256MiB

Order Statistic Set Operations

Order Statistic Set Operations

You are required to implement a data structure to maintain a set of integers (each with absolute value at most 10910^9). Initially, the set is empty. You need to support the following operations (with at most 10410^4 operations in total):

  1. Given an integer xx, report its rank, defined as the number of elements in the set strictly less than xx, plus one. (Note that xx may not be present in the set.)
  2. Query the element with rank xx (x1x\ge 1). It is guaranteed that there are at least xx elements in the set.
  3. Find the predecessor of xx in the set (i.e. the largest number in the set that is strictly less than xx). If no such number exists, output 2147483647-2147483647.
  4. Find the successor of xx in the set (i.e. the smallest number in the set that is strictly greater than xx). If no such number exists, output 21474836472147483647.
  5. Insert the integer xx into the set. It is guaranteed that xx is not present in the set before insertion.

It is guaranteed that for operations 1, 3 and 4 the set is non-empty when the operation is executed.

inputFormat

The first line contains an integer qq (1q1041\le q\le 10^4), the number of operations. Each of the following qq lines contains two integers opop and xx, where:

  • If op=1op = 1, you should output the rank of xx.
  • If op=2op = 2, you should output the element whose rank is xx.
  • If op=3op = 3, you should output the predecessor of xx.
  • If op=4op = 4, you should output the successor of xx.
  • If op=5op = 5, you should insert xx into the set.

outputFormat

For each query operation (operations 1, 2, 3, and 4), output the result on a new line.

sample

5
5 10
5 20
1 10
3 20
4 10
1

10 20

</p>