玄关 44pts TLE+WA 求调
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimze(1)
#pragma GCC optimze(3)
inline long long read(){
long long x=0;
short f=1;
char c=getchar();
while(c>57||c<48){
if(c==45) f=-1;
c=getchar();
}
while(c<58&&c>47){
x=(x<<1)+(x<<3)+(c^48);
c=getchar();
}
return x*f;
}
inline void write(long long x){
if(x<0ll) putchar(45),x=~x+1;
if(x>9ll) write(x/10);
putchar(x%10|48);
}
int n,cnt,root,ll,rr,op,x;
struct balanced_tree{
int lson,rson;
int val,priority;
int sum;
}t[11451400];
int build(int x){
t[++cnt].val=x;
t[cnt].priority=rand();
t[cnt].sum=1;
return cnt;
}
void push_up(int num){
t[num].sum=t[t[num].lson].sum+t[t[num].rson].sum+1;
}
void split(int num,int x,int &l,int &r){
if(!num){
l=r=0;
return;
}
if(t[num].val<=x){
l=num;
split(t[l].rson,x,t[l].rson,r);
}
else{
r=num;
split(t[r].lson,x,l,t[r].lson);
}
push_up(num);
}
int merge(int l,int r){
if(!l||!r) return l+r;
if(t[l].priority<=t[r].priority){
t[l].rson=merge(t[l].rson,r);
push_up(l);
return l;
}
else{
t[r].lson=merge(l,t[r].lson);
push_up(r);
return r;
}
}
void insert(int x){
split(root,x-1,ll,rr);
root=merge(merge(ll,build(x)),rr);
}
void delet(int x){
split(root,x-1,ll,rr);
int tt;
split(rr,x,tt,rr);
tt=merge(t[tt].lson,t[tt].rson);
root=merge(ll,merge(tt,rr));
}
int get_rank(int x){
if(x==0) return 1;
split(root,x-1,ll,rr);
int ans=t[ll].sum+1;
root=merge(ll,rr);
return ans;
}
int get_val(int num,int x){
int lson=t[num].lson;
int rson=t[num].rson;
if(t[lson].sum==x-1) return t[num].val;
if(t[lson].sum>=x)
return get_val(lson,x);
else return get_val(rson,x-(t[lson].sum+1));
}
int ans;
int last;
signed main(){
n=read();
int m=read();
while(n--){
int x=read();
insert(x);
}
for(int i=1;i<=m;i++){
op=read();
x=read();
x^=last;
if(op==1) insert(x);
else if(op==2) delet(x);
else if(op==3){
ans^=get_rank(x);
last=get_rank(x);
}
else if(op==4){
ans^=get_val(root,x);
last=get_val(root,x);
}
else if(op==5){
split(root,x-1,ll,rr);
ans^=get_val(ll,t[ll].sum);
root=merge(ll,rr);
last=get_val(ll,t[ll].sum);
}
else if(op==6){
split(root,x,ll,rr);
ans^=get_val(rr,1);
root=merge(ll,rr);
last=get_val(rr,1);
}
}
write(ans);
return 0;
}