POJ 3580 Splay(二)
int x,int p) { Splay(Get_kth(root,x),0); Splay(Get_kth(root,x+1),root); newnode(ch[ch[root][1]][0],ch[root][1],p); push_up(ch[root][1]); push_up(root); } void remove_root() { push_down(root); if(!ch[root][0]){ root=ch[root][1]; }else{ int t=Get_max(ch[root][0]); Splay(t,root); ch[t][1]=ch[root][1]; pre[ch[root][1]]=t; root=t; } pre[root]=0; push_up(root); } void del(int x) { Splay(Get_kth(root,x),0); remove_root(); } int Query(int L,int R) { Splay(Get_kth(root,L-1),0); Splay(Get_kth(root,R+1),root); return Min[ch[ch[root][1]][0]]; } int main(int argc, char const *argv[]) { int n,m,L,R,x; scanf("%d",&n); init(n); scanf("%d",&m); char op[10]; while(m--){ scanf("%s",op); if(op[0]=='A'){ scanf("%d%d%d",&L,&R,&x); add(L+1,R+1,x); }else if(op[0]=='D'){ scanf("%d",&L); del(L+1); }else if(op[0]=='I'){ scanf("%d%d",&L,&x); Insert(L+1,x); }else if(op[0]=='M'){ scanf("%d%d",&L,&R); printf("%d\n",Query(L+1,R+1)); }else if(op[0]=='R'){ if(op[3]=='E'){ scanf("%d%d",&L,&R); reverse(L+1,R+1); }else{ scanf("%d%d%d",&L,&R,&x); revolve(L+1,R+1,x); } } } return 0; }