ZiRanGe_Jason @ 2020-03-06 10:51:21
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<random>
using namespace std;
#define MAXN 100009
mt19937 e(666);
int cnt,root,n,m,ca;
inline int read(){
int X=0; bool flag=1; char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
if(flag) return X;
return ~(X-1);
}
inline void write(int X){
if(X<0) {X=~(X-1); putchar('-');}
if(X>9) write(X/10);
putchar(X%10+'0');
}
struct node{
int l,r;
int val,key;
int size;
}fhq[MAXN];
inline int newnode(int val){
fhq[++cnt].val=val;
fhq[cnt].key=e();
fhq[cnt].size=1;
return cnt;
}
inline void update(int x){
fhq[x].size=fhq[fhq[x].l].size+fhq[fhq[x].r].size+1;
}
void split(int now,int val,int &x,int &y){
if(!now){
x=y=0;
return;
}
if(fhq[now].val<=val)x=now,split(fhq[now].r,val,fhq[now].r,y);
else y=now,split(fhq[now].l,val,x,fhq[now].l);
update(now);
}
int merge(int x,int y){
if(!x||!y)return x+y;
if(fhq[x].key>fhq[y].key){
fhq[x].r=merge(fhq[x].r,y);
update(x);
return x;
}
else{
fhq[y].l=merge(x,fhq[y].l);
update(y);
return y;
}
}
int x,y,z;
inline void ins(int val){
split(root,val,x,y);
root=merge(merge(x,newnode(val)),y);
}
inline void del(int val){
split(root,val,x,z);
split(x,val-1,x,y);
y=merge(fhq[y].l,fhq[y].r);
root=merge(merge(x,y),z);
}
inline int rak(int val){
split(root,val-1,x,y);
int ret=fhq[x].size+1;
root=merge(x,y);
return ret;
}
inline int num(int ra){
int now=root;
while(now){
if(fhq[fhq[now].l].size+1==ra)break;
else if(fhq[fhq[now].l].size>=ra)now=fhq[now].l;
else ra-=fhq[fhq[now].l].size+1,now=fhq[now].r;
}
return fhq[now].val;
}
inline int pre(int val){
split(root,val-1,x,y);
int now=x;
while(fhq[now].r)now=fhq[now].r;
int ret=fhq[now].val;
root=merge(x,y);
return ret;
}
inline int nxt(int val){
split(root,val,x,y);
int now=y;
while(fhq[now].l)now=fhq[now].l;
int ret=fhq[now].val;
root=merge(x,y);
return ret;
}
int last=0,opt,ans;
int main(){
n=read();
m=read();
for(int i=1;i<=n;i++)ca=read(),ins(ca);
while(m--){
opt=read();
ca=read();
int cx=ca^last;
if(opt==1)ins(cx);
else if(opt==2)del(cx);
{
int out;
if(opt==3)out=rak(cx);
if(opt==4)out=num(cx);
if(opt==5)out=pre(cx);
if(opt==6)out=nxt(cx);
last=out;
ans^=out;
}
}
write(ans);
return 0;
}
by ZiRanGe_Jason @ 2020-03-06 10:51:35
FHQ Treap
by ZiRanGe_Jason @ 2020-03-06 11:00:58
没有人回复吗......
by Void_struct @ 2020-03-06 11:09:44
@C20210624吴思然 在看了
by ZiRanGe_Jason @ 2020-03-06 11:10:06
真的没人吗???
by Void_struct @ 2020-03-06 11:27:41
@C20210624吴思然 真有你的
by Void_struct @ 2020-03-06 11:28:02
我把所有都重构了
by Void_struct @ 2020-03-06 11:28:28
。。。现在过了,不知道您要不要,后面的没测,就测了样例
by ZiRanGe_Jason @ 2020-03-06 11:29:37
@ Void_struct 为什么,我真是太蒟蒻了
by Void_struct @ 2020-03-06 11:31:38
@C20210624吴思然 。。。我要是知道重构干什么,我再看看
by ZiRanGe_Jason @ 2020-03-06 11:53:04
@Void_struct
十分感谢!!!
我已经发现原因了,if(opt==2)下面的else忘打了。。。。。。
我真是太蒻了