#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<vector> #include<queue> #include<cstdlib> using namespace std; int n; int p,xxxxx,sum,ans; int tre[100000+5][5],root_val[100000+5],key[100000+5],size[100000+5]; int tot,root=0; void up(int rot) { size[rot]=size[tre[rot][0]]+size[tre[rot][1]]+1; return ; } void down(int rot) { return ; } int merge(int r1,int r2)//值1小于 2 { if (r1==0||r2==0) return r1+r2; down(r1);down(r2); if (key[r1]<key[r2]) { tre[r1][1]=merge(tre[r1][1],r2); up(r1); return r1; } else { tre[r2][0]=merge(r1,tre[r2][0]); up(r2); return r2; } } void split(int rot,int val,int &r1,int &r2) { if (rot==0) { r1=r2=0; return ; } down(rot); if (root_val[rot]<=val) { r1=rot; split(tre[rot][1],val,tre[r1][1],r2); up(r1); } else { r2=rot; split(tre[rot][0],val,r1,tre[r2][0]); up(r2); } return ; } void Insert(int &roo,int x) { tre[++tot][0]=0; tre[tot][1]=0; root_val[tot]=x; key[tot]=rand(); size[tot]=1; int r1,r2; r1=r2=0; split(roo,x,r1,r2); // cout<<r1<<” “<<tot<<” “<<r2<<” ”; r1=merge(r1,tot);up(r1); r1=merge(r1,r2);up(r1); roo=r1; return ; } void delet(int &roo,int x) { int r1,r2,r3,r4,rr; r1=r2=r3=r4=rr=0; split(roo,x,r1,r2); split(r1,x-1,r3,r4); r4=merge(tre[r4][0],tre[r4][1]); r1=merge(r3,r4); roo=merge(r1,r2); return ; } int rank(int roo,int x) { if (roo==0) return 0; int r1,r2;r1=r2=0; split(roo,x-1,r1,r2); ans=size[r1]+1; merge(r1,r2); return ans; } int num(int roo,int x) { if (roo==0) return 0; if (size[tre[roo][0]]+1==x)return root_val[roo]; if (size[tre[roo][0]]>=x) return num(tre[roo][0],x); return num(tre[roo][1],x-(size[tre[roo][0]]+1)); } int fore1(int roo,int x) { int r1,r2,rr;rr=r1=r2=0; split(roo,x-1,r1,r2); int ans1=num(r1,size[r1]); rr=merge(r1,r2); return ans1; } int back1(int roo,int x) { int r1,r2,rr;rr=r1=r2=0; split(roo,x,r1,r2); int ans1=num(r2,1); rr=merge(r1,r2); return ans1; } int main() { cin>>n; for (int i=1;i<=n;i++) { scanf(“%d%d”,&p,&xxxxx); if (p==1) Insert(root,xxxxx); else if (p==2) delet(root,xxxxx);else if (p==3) printf(“%d\n”,rank(root,xxxxx));else if (p==4) printf(“%d\n”,num(root,xxxxx));else if (p==5) printf(“%d\n”,fore1(root,xxxxx));else if (p==6) printf(“%d\n”,back1(root,xxxxx)); } return 0; }