Lacrymabre @ 2022-01-24 21:48:10
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<time.h>
#define ll long long
#define _it set<node>::iterator
#define MAX 0x7fffffff
#define INF 0X3fffffff
#define N 2000005
using namespace std;
inline long long read(){
ll f=1,s=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
return s*f;
}
struct fhq{
ll l,r,siz,val,p;
#define ls(x) t[x].l
#define rs(x) t[x].r
#define sz(x) t[x].siz
#define v(x) t[x].val
#define p(x) t[x].p
}t[N];
ll rd(){return rand();}
ll n,m,ans;
ll cnt,l,r,root,p,op,x,last;
void pushup(ll x){
t[x].siz=t[t[x].l].siz+t[t[x].r].siz+1;
}
ll build(ll x){
t[++cnt].siz=1;
t[cnt].l=t[cnt].r=0;
t[cnt].val=x;t[cnt].p=rand();
return cnt;
}
void spilt_val(ll now,ll val,ll &x,ll &y){
if(!now){
x=y=0;
return;
}
if(t[now].val<=val){
x=now;
spilt_val(t[now].r, val, t[now].r, y);
}else{
y=now;
spilt_val(t[now].l,val,x,t[now].l);
}
pushup(now);
}
void spilt_siz(ll now,ll siz,ll &x,ll &y){
if(!now){
x=y=0;
return;
}
if(t[ls(now)].siz+1<=siz){
x=now;
spilt_siz(t[now].r,siz-t[ls(now)].siz-1,t[now].r,y);
}else{
y=now;
spilt_siz(t[now].l,siz,x,t[now].l);
}
pushup(now);
}
ll merge(ll x,ll y){
if(!x||!y) return (x+y);
if (v(x)>v(y)) swap(x, y);
if(p(x)<p(y)){
t[x].r=merge(t[x].r,y);
pushup(x);
return x;
}else{
t[y].l=merge(t[y].l,x);
pushup(y);
return y;
}
}
void insert(ll x){
spilt_val(root,x,l,r);
build(x);
root=merge(merge(l,cnt),r);
}
void qrank(ll x){
spilt_val(root,x-1,l,r);
ll res=t[l].siz+1;
root=merge(l,r);
last=res;
ans^=res;
}
ll qkth(ll now,ll k){
if(!now) return 1;
if(k<=t[t[now].l].siz) return qkth(t[now].l,k);
else if(k==t[t[now].l].siz+1) return now;
else{
k-=(t[t[now].l].siz+1);
return qkth(t[now].r,k);
}
}
void deletle(ll x){
spilt_val(root,x,l,r);
spilt_val(l,x-1,l,p);
p=merge(t[p].l,t[p].r);
root=merge(merge(l,p),r);
}
void frm(ll x){
spilt_val(root,x-1,l,r);
ll now=l;
while(t[now].r) now=t[now].r;
ll res=t[now].val;
root=merge(l,r);
ans^=res;
last=res;
}
void net(ll x){
spilt_val(root,x,l,r);
ll now=r;
while(t[now].l) now=t[now].l;
ll res=t[now].val;
root=merge(l,r);
ans^=res;
last=res;
}
int main(){
srand(time(0)*114514+1919810);
n=read();m=read();
for(int i=1;i<=n;i++) insert(read());
while(m-->0){
op=read();x=read();x^=last;
;;;; if(op==1) insert(x);
else if(op==2) deletle(x);
else if(op==3) qrank(x);
else if(op==4) ans^=t[qkth(root,x)].val;
else if(op==5) frm(x);
else if(op==6) net(x);
}
cout<<ans;
return 0;
}
by 10circle @ 2022-01-24 21:55:29
by Lacrymabre @ 2022-01-24 22:00:57
@10circle thanks