-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfhq1.cpp
More file actions
105 lines (104 loc) · 2.03 KB
/
Copy pathfhq1.cpp
File metadata and controls
105 lines (104 loc) · 2.03 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include<bits/stdc++.h>
using namespace std;
#define N 2000006
int n,m;
int val[N],tree[N][2],cv[N],siz[N],cnt,root,x,y,z;
inline int read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')w=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
inline int r()
{
return rand()%(1<<20);
}
inline void update(int x)
{
siz[x]=1+siz[tree[x][0]]+siz[tree[x][1]];
}
inline int newnode(int x)
{
val[++cnt]=x;
cv[cnt]=r();
siz[cnt]=1;
return cnt;
}
inline int merge(int x,int y)//x<=y
{
// cout<<'*'<<x<<' '<<y;
if(!x or !y)return x+y;
if(cv[x]>=cv[y])
{
tree[y][0]=merge(x,tree[y][0]);
update(y);return y;
}
else
{
tree[x][1]=merge(tree[x][1],y);
update(x);return x;
}
}
inline void split(int now,int k,int &x,int &y)//x<=k<=y
{
// cout<<'*'<<now<<' '<<k<<endl;
if(!now){
x=y=0;return;
}
if(val[now]<=k)x=now,split(tree[now][1],k,tree[now][1],y);
else y=now,split(tree[now][0],k,x,tree[now][0]);
update(now);
}
inline int kth(int now,int k)
{
// cout<<'*'<<now<<' '<<k<<endl;
if(siz[tree[now][0]]>=k)return kth(tree[now][0],k);
else if(1+siz[tree[now][0]]==k)return now;
else return kth(tree[now][1],k-siz[tree[now][0]]-1);
}
signed main()
{
srand(time(0));
cin>>n>>m;
int c;
for(int i=1;i<=n;i++)
{
cin>>c;
//c=read();
if(i==1)root=newnode(c);
else
{
split(root,c,x,y);
root=merge(merge(x,newnode(c)),y);
}
}
int op,las=0,ans=0;
for(int i=1;i<=m;i++)
{
op=read();
c=read();
//cin>>op>>c;
c^=las;
// cout<<op<<' '<<las<<' '<<c<<endl;
switch(op)
{
case 1:split(root,c,x,y);root=merge(merge(x,newnode(c)),y);break;
case 2:split(root,c,x,y);split(x,c-1,x,z);z=merge(tree[z][0],tree[z][1]);root=merge(merge(x,z),y);break;
case 3:split(root,c-1,x,y);las=siz[x]+1;root=merge(x,y);ans^=las;break;
case 4:las=val[kth(root,c)];ans^=las;break;
case 5:split(root,c-1,x,y);las=val[kth(x,siz[x])];root=merge(x,y);ans^=las;break;
case 6:split(root,c,x,y);las=val[kth(y,1)];root=merge(x,y);ans^=las;break;
}
}
cout<<ans<<endl;
}