-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLOJ-1087.cpp
88 lines (88 loc) · 1.61 KB
/
LOJ-1087.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<bits/stdc++.h>
using namespace std;
inline int RI() {
int ret = 0, flag = 1,ip = getchar_unlocked();
for(; ip < 48 || ip > 57; ip = getchar_unlocked()) {
if(ip == 45) {
flag = -1;
ip = getchar_unlocked();
break;
}
}
for(; ip > 47 && ip < 58; ip = getchar_unlocked())
ret = ret * 10 + ip - 48 ;
return flag * ret;
}
int n,q,tree[200005],arr[200005];
inline void update(int ii,int vv){
while(ii<=(n+q)){
tree[ii]+=vv;
ii+=((ii)&(-ii));
}
return;
}
inline int read(int ii){
int ret=0;
while(ii>0){
ret+=tree[ii];
ii-=((ii)&(-ii));
}
return ret;
}
int main() {
int t;
t=RI();
//scanf("%d",&t);
for(int z=1;z<=t;z++){
n=RI();q=RI();
//scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++){
arr[i]=RI();
//scanf("%d",&arr[i]);
}
memset(tree,0,sizeof(tree));
for(int i=1;i<=n;i++)update(i,1);
cout<<"Case "<<z<<":\n";
int a=q,lim=n;
while(a--){
char c=0;
int d;
// for(int i=1;i<=(n+q);i++){
// cout<<read(i)<<" ";
// }cout<<endl;
while(c!='a' && c!='c'){
c=getchar_unlocked();
}
d=RI();
//scanf(" %c %d",&c,&d);
if(c=='a'){
arr[n+1]=d;
n++;
lim++;
update(n,1);
}else{
if(d>lim){
cout<<"none\n";
continue;
}
int low=1,high=n+q,mid;
while((high-low)>4){
mid=(low+high)>>1;
if(read(mid)>=d)high=mid;
else low=mid;
}
for(;low<=high;low++){
if(read(low)==d)break;
}
if(low>n){
cout<<"none\n";
continue;
}
cout<<arr[low]<<"\n";
update(low,-1);
lim--;
}
}
}
return 0;
}