KFSTD - Help the statistics department

no tags 

In the statistics department of the Kingdom of Byteland the programmers have to maintain all the dynamic information efficiently. The Census data for the current decade was recently collected in Byteland, and now the data is to be used to compute some interesting statistics. The programmers at the statistics department are not very smart, hence they are seeking the help of a bright student i.e. you :). The problem is as follows:

We need to maintain a dynamic list of integers which is initially empty under the following 4 operations:

Add(x) :- Add x to the dynamic list
Delete(x) :- Delete one occurrence of x from the dynamic list
ReportKth(k) :- Print the 1-based Kth smallest element in the list
ReportRank(x):- Report the 1-based rank of x (1 + Number of elements less than x)

Input

First line of the input contains T, number of test cases.
First line of each test case contains Q, number of operations.
Each of the next Q lines is of the following form:
K X

If K = 1 then perform Add(x)
If K = 2 then perform Delete(x)
If K = 3 then perform ReportKth(x)
If K = 4 then perform ReportRank(x)

Output

For each operation of the type 3 OR 4 print one line containing the required result. It is guaranteed that the number x given at the time of delete operation is always present in the set. It is also guaranteed that x in the operation ReportRank is no more than number of elements in the list at that moment.

Sample Input

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

Sample Output

2
3
1

Constraints

1 <= T <= 10
1 <= Q <= 10^5
1 <= X <= 10^5
1 <= K <= 4


hide comments

Added by:rizwan hudda
Date:2012-09-04
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Kodefest 2012 IITK - Own problem