1087 - Diablo
Time Limit: 2 second(s)
Memory Limit: 64 MB
All of you must have played the game 'Diablo'. It's an exclusive game to play. In this game the main opponent of you is Diablo. If you kill him the game finishes. But as usual, Diablo is smarter than you.
Diablo has a large number of army. Diablo arranges them in a line in any arbitrary order and everyone is given an integer id. Each time Diablo either adds one army in the end or he calls for the kth army (from left) from the line. Then the army gets out and it attacks you.
Since you are a great magician, you can read Diablo's mind. Now you want to find the id of the armies who are about to attack you.
Input starts with an integer T (≤ 5), denoting the number of test cases.
The first line of each case is a blank line. The next line contains two integers n (0 ≤ n ≤ 105), denoting the number of the initial army and q (1 ≤ q ≤ 50000) representing the number of queries. The next line contains n space separated integers. The ith integer of this line denotes the id of the ith person. Each of these integers will be positive and fits into a 32 bit signed integer. Each of the next q lines will contain a query, of the form:
a p (add a person at the end of the line whose id is p)
c k (call the kth person from the line (from left), k is a positive 32 bit signed integer)
For each case of input, print the case number in a line. Then for all the queries 'c k' you have to print the id of the kth person or 'none' if there is none.
2
5 5
6 5 3 2 1
c 1
c 1
a 20
c 4
c 4
2 1
18811 1991
c 1
Case 1:
6
5
20
none
Case 2:
18811
Dataset is huge, use faster i/o methods.
PROBLEM SETTER: JANE ALAM JAN
思路:线段数求第k大树,单点更新;
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
手机扫一扫
移动阅读更方便
你可能感兴趣的文章