4pts 五彩斑斓 从隔壁普通版搬过来的
#include<bits/stdc++.h>
#include<ctime>
using namespace std;
int id,root;
struct node{
int cnt,ls,rs,val,key,size;
}tree[400005];
void pushup(int p){
tree[p].size=tree[p].cnt+tree[tree[p].ls].size+tree[tree[p].rs].size;
}
int newnode(int n){
tree[++id].size=1;
tree[id].cnt=1;
tree[id].key=n;
tree[id].val=rand();
return id;
}
void build(){
newnode(-1e9);
newnode(1e9);
root=1;
tree[1].rs=2;
pushup(1);
}
void zig(int &p){
int q=tree[p].ls;
tree[p].ls=tree[q].rs;
tree[q].rs=p;
p=q;
pushup(tree[p].rs);
pushup(p);
}
void zag(int &p){
int q=tree[p].rs;
tree[p].rs=tree[q].ls;
tree[q].ls=p;
p=q;
pushup(tree[p].ls);
pushup(p);
}
void insert(int &p,int x){
if(!p){
p=newnode(x);
return;
}
else{
if(x==tree[p].key)tree[p].cnt++;
else{
if(tree[p].key>x){
insert(tree[p].ls,x);
if(tree[tree[p].ls].val>tree[p].val)
zig(p);
}
else{
insert(tree[p].rs,x);
if(tree[tree[p].rs].val>tree[p].val)
zag(p);
}
}
pushup(p);
}
}
void del(int &p,int x){
if(!p)return;
if(tree[p].key==x){
if(tree[p].cnt>1)
tree[p].cnt--;
else{
if(tree[p].ls||tree[p].rs){
if(!tree[p].rs||tree[tree[p].ls].val>tree[tree[p].rs].val){
zig(p);
del(tree[p].rs,x);
}
else{
zag(p);
del(tree[p].ls,x);
}
}
else
p=0;
}
}
else if(tree[p].key>x){
del(tree[p].ls,x);
}
else{
del(tree[p].rs,x);
}
pushup(p);
}
int ask1(int p,int x){
if(!p)return 1;
if(tree[p].key==x)
return tree[tree[p].ls].size+1;
else if(tree[p].key>x)
return ask1(tree[p].ls,x);
else
return tree[tree[p].ls].size+tree[p].cnt+ask1(tree[p].rs,x);
}
int ask2(int p,int x){
if(!p)return 1e9;
if(tree[tree[p].ls].size>=x)
return ask2(tree[p].ls,x);
else if(tree[tree[p].ls].size+tree[p].cnt>=x)
return tree[p].key;
else
return ask2(tree[p].rs,x-tree[tree[p].ls].size-tree[p].cnt);
}
int main(){
srand(time(0));
build();
int n,t;
cin>>n>>t;
for(int i=1;i<=n;i++){
int x;
cin>>x;
insert(root,x);
}
int last=0,ans1=0;
while(t--){
int opt,x;
cin>>opt>>x;x^=last;
if(opt==1){
insert(root,x);
}
else if(opt==2){
del(root,x);
}
else if(opt==3){
last=ask1(root,x)-1;
}
else if(opt==4){
last=ask2(root,x+1);
}
else if(opt==5){
last=ask2(root,ask1(root,x)-1);
}
else if(opt==6){
last=ask2(root,ask1(root,x+1));
}
ans1^=last;
}
cout<<ans1;
return 0;
}