(╯-_-) ╯╧╧
Here is the error code.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMAXN 300050#defineINF 2147483646using namespacestd;intn,m,a[maxn],x,y;inttree[maxn][3],size[maxn],fath[maxn],val[maxn],root,hash[maxn],rr=0;Chars[Ten];voidPushup (intNow ) {Size[now]=size[tree[now][1]]+size[tree[now][2]]+1;}voidResetintx) {Fath[x]=tree[x][1]=tree[x][2]=0; SIZE[X]=1;}voidSets (intXinty) {swap (fath[x],fath[y]); if(fath[x]==y) {fath[x]=fath[y];fath[y]=x; }}voidBuildint&now,intLeftintRightintfather) { if(Left>right)return; intMid= (left+right) >>1; now=mid; Fath[now]=father;val[now]=A[mid]; Build (tree[now][1],left,mid-1, now); Build (tree[now][2],mid+1, Right,now); Pushup (now);}voidRotateintXint&k) { inty=fath[x],z=Fath[y],l,r; if(tree[y][1]==X) l=1;ElseL=2; R=3-l; if(y==k) k=x; Else { if(tree[z][1]==y) tree[z][1]=x; Elsetree[z][2]=x; } Fath[x]=z;fath[y]=x;fath[tree[x][r]]=y; TREE[Y][L]=tree[x][r];tree[x][r]=y; Pushup (y);p ushup (x);}voidSplay (intXint&k) { while(x!=k) {inty=fath[x],z=Fath[y]; if(y!=k) {if((tree[y][1]==x) ^ (tree[z][1]==y)) rotate (x,k); Elserotate (y,k); } rotate (x,k); }}intGet_pre (intx) { intret=tree[x][1]; while(tree[ret][2]) ret=tree[ret][2]; returnret;}intGet_sub (intx) { intret=tree[x][2]; while(tree[ret][1]) ret=tree[ret][1]; returnret;}voidDelete_ (intx) {splay (x,root); intPre=Get_pre (root); intls=tree[x][1],rs=tree[x][2]; Root=ls;fath[ls]=fath[rs]=0; splay (pre,root); tree[root][2]=rs;fath[rs]=root;pushup (root); Reset (x);}intFind_kth (intNowintx) { intr=size[tree[now][1]]; if(X<=R)returnFind_kth (tree[now][1],x); Else if(x>r+1)returnFind_kth (tree[now][2],x-r-1); Else{RR=Now ; returnNow ; }}intGet_rank (intx) {splay (x,root); returnsize[tree[root][1]];}intMain () {scanf ("%d%d",&n,&m); for(intI=1; i<=n;i++) {scanf ("%d", &a[i+1]); Hash[a[i+1]]=i+1; } a[1]=n+1; a[n+2]=n+2; Build (Root,1, n+2,0); for(intI=1; i<=m;i++) {scanf ("%s", s); if(s[0]=='T') {scanf ("%d",&x); Delete_ (Hash[x]); Y=find_kth (Root,1); Splay (Y,root); intrs=tree[root][2]; Reset (root); Fath[root]=hash[x];fath[rs]=hash[x];tree[hash[x]][1]=root;tree[hash[x]][2]=rs;pushup (hash[x]); Root=Hash[x]; Splay ((n+3) >>1, Root); } Else if(s[0]=='B') {scanf ("%d",&x); Delete_ (Hash[x]); Y=find_kth (root,n+1); Splay (Y,root); intls=tree[root][1]; Reset (root); Fath[root]=hash[x];fath[ls]=hash[x];tree[hash[x]][2]=root;tree[hash[x]][1]=ls;pushup (hash[x]); Root=Hash[x]; Splay ((n+3) >>1, Root); } Else if(s[0]=='I') {scanf ("%d%d",&x,&y); if(y==0)Continue; Else if(y==-1) { intPre=Get_pre (hash[x]); Sets (Pre,hash[x]); } Else { intsub=get_sub (hash[x]); Sets (Hash[x],sub); } splay (Hash[x],root); } Else if(s[0]=='A') {scanf ("%d",&x); printf ("%d\n", Get_rank (Hash[x])-1); Splay (Hash[x],root); } Else{RR=0; scanf ("%d",&x); printf ("%d\n", Val[find_kth (root,x+1)]); Splay (Rr,root); } } return 0;}
Bzoj 1861 Bookshelf