卢本伟!! @ 2020-04-07 21:42:12
/* 西江月·证明
即得易见平凡,仿照上例显然。
留作习题答案略, 读者自证不难。
反之亦然同理,推论自然成立。
略去过程QED,由上可知证毕。*/
#include<set>
#include<map>
#define mod 10
#include<list>
#include<cmath>
#include<queue>
#include<ctime>
#include<stack>
#include<ctime>
#include<bitset>
#include<memory>
#include<cstdio>
#include<string>
#include<sstream>
#include<utility>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rg register
#define bll __int128
#define ll long long
#define inf 21432409
#define ull unsigned long long
#define debug() cout<<"SOSOSOSOSOSOSOS!!!!!!!!!"
#define C(i,j) dp[i+1][j+1]
using namespace std;
int read(){
int ans=0,f=1;char a=getchar();while(a>'9'||a<'0'){if(a=='-')f=(-1);a=getchar();}
while(a>='0'&&a<='9')ans=(ans<<3)+(ans<<1)+a-'0',a=getchar();return ans*f;
}//一条long long的黄金分割线---------------------------------------------------------------------------------------------
int root,sum,n,last=0,ans;
struct jd{
int lson,rson,now_val,siz;
}d[1000005];
int newnode(int w){
d[++sum].now_val=w;
d[sum].siz=1;
d[sum].lson=d[sum].rson=0;
return sum;
}
void upt(const int &k){d[k].siz=d[d[k].lson].siz+d[d[k].rson].siz+1;}
void spilt(int now,int mid,int &x,int &y){
if(!now)x=y=0;
else if(d[now].now_val<=mid)x=now,spilt(d[now].rson,mid,d[now].rson,y),upt(now);
else y=now,spilt(d[now].lson,mid,x,d[now].lson),upt(now);
}//三行spilt ! ! !
void spilt_siz(int now,int siz,int &x,int &y){
if(!now)x=y=0;
else if(d[d[now].lson].siz<siz)x=now,
spilt(d[now].rson,siz-d[d[now].lson].siz-1,d[now].rson,y);
else y=now,
spilt(d[now].lson,siz,x,d[now].lson);
upt(now);
}
int _merge(int x,int y){
if(!x||!y)return x+y;
else if(99999998%(d[x].siz+d[y].siz)<d[x].siz){
d[x].rson=_merge(d[x].rson,y),upt(x);
return x;
}
else{
d[y].lson=_merge(x,d[y].lson),upt(y);
return y;
}
}
int x,y,z;
void insert(int val){
spilt(root,val,x,y);
root=_merge(_merge(x,newnode(val)),y);
}
void _delete(int val){
spilt(root,val,x,z),spilt(x,val-1,x,y);
y=_merge(d[y].lson,d[y].rson);
root=_merge(_merge(x,y),z);
}
void getrank(int val){//valのrank
spilt(root,val-1,x,y);
last=d[x].siz+1;
root=_merge(x,y);
}
void getnum(int rank){
int now=root;
while(now){
if(d[d[now].lson].siz+1==rank)
break;
else if(d[d[now].lson].siz>=rank)
now=d[now].lson;
else
rank-=d[d[now].lson].siz+1,now=d[now].rson;
}
last=d[now].now_val;
}
void pre(int val){
spilt(root,val-1,x,y);
int now=x;
while(d[now].rson)now=d[now].rson;
last=d[now].now_val;
root=_merge(x,y);
}
void nxt(int val){//valのnxt
spilt(root,val,x,y);
int now=y;
while(d[now].lson)now=d[now].lson;
last=d[now].now_val;
root=_merge(x,y);
}
int main()
{
n=read();int m=read(),i;
for(i=1;i<=n;i++)insert(read());
for(i=1;i<=m;i++){
int opt=read(),x=read()^last;
if(!(opt-1))insert(x);
else if(!(opt-2))_delete(x);
else if(!(opt-3))getrank(x);
else if(!(opt-4))getnum(x);
else if(!(opt-5))pre(x);
else if(!(opt-6))nxt(x);
if(opt>=3)ans^=last;
}
cout<<ans;
return 0;
}
by xhQYm @ 2020-04-07 21:43:13
名字好评。(大雾(滑稽(逃
by 卢本伟!! @ 2020-04-07 21:44:43
by 卢本伟!! @ 2020-04-07 21:45:08
@qym2008 (大雾
by 卢本伟!! @ 2020-04-07 21:47:12
看看呗
by 一只蠢萌de诱受 @ 2020-04-07 21:48:10
名字好评。(大雾(滑稽(逃
by 卢本伟!! @ 2020-04-07 21:51:47
巨佬们看看呗,不要再好评了!!!
by KLNG7 @ 2020-04-07 21:53:28
好诗
by qsceszthn @ 2020-04-07 21:56:34
lbwnb
by JRzyh @ 2020-04-07 22:06:21
学学OI传记
by Reaepita @ 2020-04-07 22:06:48
好诗