1087 - Diablo
阅读原文时间:2023年07月08日阅读:1

1087 - Diablo

  

PDF (English)

Statistics

Forum

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

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)

Output

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.

Sample Input

Output for Sample Input

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

Notes

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
8 #include
9 using namespace std;
10 typedef long long LL;
11 int tree[5000000];
12 int ans[160005];
13 int id[160000];
14 int flag[160000];
15 void build(int l,int r,int k,int u);
16 int ask(int l,int r,int k,int m);
17 void up(int k);
18 void in(int x);
19 int main(void)
20 {
21 int i,j,k;
22 scanf("%d",&k);
23 int s;
24 int n,m;
25 int gg=0;
26 for(s=1; s<=k; s++) 27 { 28 scanf("%d %d",&n,&m); 29 for(i=1; i<=n; i++) 30 { 31 scanf("%d",&ans[i]); 32 } 33 memset(flag,0,sizeof(flag)); 34 for(i=n+1; i<=160000; i++) 35 { 36 flag[i]=1; 37 } 38 build(1,160000,0,n); 39 gg=n; 40 int cn=n; 41 printf("Case %d:\n",s); 42 while(m--) 43 { 44 char a[2]; 45 int x; 46 scanf("%s %d",a,&x); 47 if(a[0]=='c') 48 { 49 if(gg=ans)
118 {
119 return ask(l,(l+r)/2,2*k+1,ans);
120 }
121 else if(tree[2*k+1]=0)
133 {
134 tree[k]=tree[2*k+1]+tree[2*k+2];
135 if(k==0)
136 return ;
137 k=(k-1)/2;
138 }
139 }
140 void in(int x)
141 {
142 int cc=id[x];
143 tree[cc]=1;
144 if(cc==0)return ;
145 cc=(cc-1)/2;
146 while(cc>=0)
147 {
148 tree[cc]=tree[2*cc+1]+tree[2*cc+2];
149 if(cc==0)
150 return ;
151 cc=(cc-1)/2;
152 }
153 }

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章