求调
#include <bits/stdc++.h>
using namespace std;
#define lson t[now].ch[0]
#define rson t[now].ch[1]
struct fhq_treap
{
int ch[2];
int pri,val;
int fa;
int size;
}t[100010];
int cnt,root;
int newnode(int i)
{
t[++cnt].pri=rand();
t[cnt].val=i;
t[cnt].fa=0;
return cnt;
}
void update(int now)
{
t[now].size=t[lson].size+t[rson].size+1;
}
int merge(int x,int y)
{
if(x==0||y==0)
return x+y;
if(t[x].pri>t[y].pri)
{
t[x].ch[1]=merge(t[x].ch[1],y);
update(x);
return x;
}
else
{
t[y].ch[0]=merge(x,t[y].ch[0]);
update(y);
return y;
}
}
void split(int now,int key,int &x,int &y)
{
if(now==0)
{
x=0,y=0;
return ;
}
if(t[now].val<=key)
{
x=now;
split(t[now].ch[1],key,t[now].ch[1],y);
}
else
{
y=now;
split(t[now].ch[0],key,x,t[now].ch[0]);
}
update(now);
}
void insert(int d)
{
int t=newnode(d);
int x,y;
split(root,d,x,y);
root=merge(x,t);
root=merge(root,y);
}
void del(int d)
{
int x,y,z,u;
split(root,d,x,z);
split(x,d-1,u,y);
y=merge(t[y].ch[0],t[y].ch[1]);
root=merge(u,y);
root=merge(root,z);
}
int find_id(int d)
{
int x,y;
split(root,d-1,x,y);
cout<<t[x].size+1<<endl;
root=merge(x,y);
}
int find_xth(int now,int x)
{
if(t[lson].size==x-1)
return t[now].val;
if(t[lson].size>=x)
return find_xth(t[now].ch[0],x);
return find_xth(t[now].ch[1],x-t[lson].size-1);
}
int main()
{
int n;
cin>>n;
int x,y;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
if(x==1)
{
insert(y);
}
if(x==2)
del(y);
if(x==3)
{
find_id(y);
}
if(x==4)
{
cout<<find_xth(root,y)<<endl;
}
if(x==5)
{
int u,v;
split(root,y-1,u,v);
cout<<find_xth(u,t[u].size)<<endl;
root=merge(u,v);
}
if(x==6)
{
int u,v;
split(root,y,u,v);
cout<<find_xth(v,1)<<endl;
root=merge(u,v);
}
}
return 0;
}