Withers @ 2022-08-31 16:51:50
RT,过的了模板题
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1.5e6+5;
struct node
{
int l,r;
int val,key;
int size;
}f[maxn];
int cnt,root,x,y,z;
mt19937 rnd(233);
inline int newnode(int val)
{
f[++cnt].val=val;
f[cnt].key=rnd();
f[cnt].size=1;
return cnt;
}
inline void update(int now)
{
f[now].size=f[f[now].l].size+f[f[now].r].size+1;
}
void split(int now,int val,int &x,int &y)
{
if(!now) x=y=0;
else
{
if(f[now].val<=val)
{
x=now;
split(f[now].r,val,f[now].r,y);
}
else
{
y=now;
split(f[now].l,val,x,f[now].l);
}
update(now);
}
}
int merge(int x,int y)
{
if(!x||!y) return x+y;
if(f[x].key>f[y].key)
{
f[x].r=merge(f[x].r,y);
update(x);
return x;
}
else
{
f[y].l=merge(x,f[y].l);
update(y);
return y;
}
}
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(f[y].l,f[y].r);
root=merge(merge(x,y),z);
}
inline int getrank(int val)
{
split(root,val-1,x,y);
z=f[x].size+1;
root=merge(x,y);
return z;
}
inline int getnum(int rank)
{
int now=root;
while(now)
{
if(f[f[now].l].size+1==rank)
break;
else if(f[f[now].l].size>=rank)
now=f[now].l;
else
{
rank-=f[f[now].l].size+1;
now=f[now].r;
}
}
return f[now].val;
}
inline int pre(int val)
{
split(root,val-1,x,y);
int now = x;
while(f[now].r)
now = f[now].r;
root=merge(x,y);
return f[now].val;
}
inline int nxt(int val)
{
split(root,val,x,y);
int now = y;
while(f[now].l)
now = f[now].l;
root=merge(x,y);
return f[now].val;
}
int t,op,p,n;
int lst=0,ans=0;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>t;
for(int i=1;i<=n;i++)
{
cin>>p;
ins(p);
}
while(t--)
{
cin>>op>>p;
if(op>=3) p^=lst;
if(op==1) ins(p);
else if(op==2) del(p);
else if(op==3) lst=getrank(p);
else if(op==4) lst=getnum(p);
else if(op==5) lst=pre(p);
else lst=nxt(p);
if(op>=3) ans^=lst;
}
cout<<ans;
return 0;
}
by Withers @ 2022-08-31 16:55:42
打错了,是52分qwq
by Galex @ 2022-08-31 17:24:58
by Galex @ 2022-08-31 17:26:17
无论如何都要
by Galex @ 2022-08-31 17:26:28
@Withers
by Withers @ 2022-08-31 17:28:46
@Galex 啊,过了,我智障了