1584: 数据结构

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:7 Solved:6

Description

有一种数据结构,可以用来维护一些数( 都是 lns="http://www.w3.org/1998/Math/MathML">109 以内的数字)的集合,最开始时集合是空的。其中需要提供以下操作,操作次数 lns="http://www.w3.org/1998/Math/MathML"> 不超过 lns="http://www.w3.org/1998/Math/MathML">104

  1. 查询 lns="http://www.w3.org/1998/Math/MathML"> 数的排名(排名定义为比当前数小的数的个数 lns="http://www.w3.org/1998/Math/MathML">+1。若有多个相同的数,应输出最小的排名)。
  2. 查询排名为 lns="http://www.w3.org/1998/Math/MathML"> 的数。
  3. 求 lns="http://www.w3.org/1998/Math/MathML"> 的前驱(前驱定义为小于 lns="http://www.w3.org/1998/Math/MathML">,且最大的数)。若未找到则输出 lns="http://www.w3.org/1998/Math/MathML">2147483647
  4. 求 lns="http://www.w3.org/1998/Math/MathML"> 的后继(后继定义为大于 lns="http://www.w3.org/1998/Math/MathML">,且最小的数)。若未找到则输出 lns="http://www.w3.org/1998/Math/MathML">2147483647
  5. 插入一个数 lns="http://www.w3.org/1998/Math/MathML">

Input

第一行是一个整数 lns="http://www.w3.org/1998/Math/MathML">,表示操作次数。

接下来 lns="http://www.w3.org/1998/Math/MathML"> 行,每行两个整数 lns="http://www.w3.org/1998/Math/MathML">,,分别表示操作序号以及操作的参数 lns="http://www.w3.org/1998/Math/MathML">

Output

输出有若干行。对于操作 lns="http://www.w3.org/1998/Math/MathML">1,2,3,4,输出一个整数,表示该操作的结果。

Sample Input Copy

7
5 1
5 3
5 5
1 3
2 2
3 3
4 3

Sample Output Copy

2
3
1
5