BZOJ 3223 Splay区间翻转
思路:
区间翻转的裸题 终于tm理解splay了……
//By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 155555 int n,m,root,size ,ch [2],fa ,rev ,v ; void push_up(int x){size[x]=size[ch[x][0]]+size[ch[x][1]]+1;} int build(int l,int r){ if(l>r)return 0; if(l==r){size[l]=1,v[l]=l-1;return l;} int mid=(l+r)>>1;v[mid]=mid-1; ch[mid][0]=build(l,mid-1);fa[ch[mid][0]]=mid; ch[mid][1]=build(mid+1,r);fa[ch[mid][1]]=mid; push_up(mid); return mid; } void rotate(int p){ int q=fa[p],y=fa[q],f=(ch[q][1]==p); ch[q][f]=ch[p][!f],fa[ch[q][f]]=q; ch[p][!f]=q;fa[q]=p;fa[p]=y; if(y){ if(ch[y][0]==q)ch[y][0]=p; else ch[y][1]=p; }push_up(q); } void Splay(int x,int tp){ for(int y;y=fa[x];rotate(x)){ if(y==tp)break; if(fa[y]!=tp){ if((ch[y][0]==x)^(ch[fa[y]][0]==y))rotate(x); else rotate(y); } }push_up(x); if(!tp)root=x; } void push_down(int x){ if(rev[x]){ rev[ch[x][0]]^=1,rev[ch[x][1]]^=1; swap(ch[x][0],ch[x][1]); rev[x]=0; } } int find(int x,int num){ push_down(x); int sz=size[ch[x][0]]; if(sz+1==num)return x; else if(sz+1>num)return find(ch[x][0],num); else return find(ch[x][1],num-sz-1); } void reverse(int l,int r){ int y=find(root,l);Splay(y,0); Splay(find(root,r+2),y); rev[ch[ch[root][1]][0]]^=1; } void dfs(int x){ push_down(x); if(ch[x][0])dfs(ch[x][0]); if(v[x]&&v[x]!=n+1)printf("%d ",v[x]); if(ch[x][1])dfs(ch[x][1]); } int main(){ scanf("%d%d",&n,&m); root=build(1,n+2); for(int i=1;i<=m;i++){ int l,r; scanf("%d%d",&l,&r); reverse(l,r); } dfs(root); }
- splay区间翻转(bzoj 3223: Tyvj 1729 文艺平衡树)
- splay区间翻转bzoj 3223(tyvj 1729)文艺平衡树题解
- bzoj 3223: Tyvj 1729 文艺平衡树(splay 模板题 区间翻转)
- BZOJ 3223 Splay区间翻转
- splay处理区间翻转例题【BZOJ 3223】 Tyvj 1729 文艺平衡树
- bzoj3223[Tyvj 1729] 文艺平衡树(splay模板题:区间翻转)
- 区间翻转 bzoj 3223 文艺平衡树 (splay)
- bzoj3223区间翻转
- [SPLAY维护区间][BZOJ 3223][TYVJ 1729]文艺平衡树
- bzoj 1552: [Cerc2007]robotic sort && bzoj 3506: [Cqoi2014]排序机械臂(splay区间翻转)
- BZOJ3506 BZOJ1552 排序机械臂 Splay区间翻转(数组版自底向上的写法)
- 【BZOJ3223】文艺平衡树,Splay反转区间
- bzoj3223 文艺平衡树(平衡树区间翻转)
- bzoj3223 Tyvj 1729 文艺平衡树(Splay Tree+区间翻转)
- [BZOJ]3223 文艺平衡树 区间翻转
- bzoj3223 Tyvj 1729 文艺平衡树(Splay Tree+区间翻转)
- bzoj3223 文艺平衡树 codevs3303 翻转区间
- BZOJ 3223 文艺平衡树 [codevs3303翻转区间]
- BZOJ 3223 浅谈SPLAY伸展树算法区间翻转
- BZOJ 3223 Tyvj 1729 文艺平衡树(Splay)