[BZOJ3223]文艺平衡树(平衡树splay)
来源:互联网 发布:三菱系统编程视频教程 编辑:程序博客网 时间:2024/05/05 15:18
题目描述
传送门
题解
平衡树的模板题。有区间操作,打标记。
代码
#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int max_n=1e5+5;const int INF=1e9;int n,m,x,y;int root,sz;int ch[max_n][2],f[max_n],delta[max_n],size[max_n],key[max_n];int a[max_n];inline bool get(int x){ return ch[ f[x] ][1]==x;}inline void update(int x){ size[x]=size[ ch[x][0] ]+size[ ch[x][1] ]+1;}inline void pushdown(int x){ if (x&&delta[x]){ delta[ ch[x][0] ]^=1; delta[ ch[x][1] ]^=1; swap(ch[x][0],ch[x][1]); delta[x]=0; }}inline void rotate(int x){ pushdown(f[x]); pushdown(x); int old=f[x],oldf=f[old],which=get(x); ch[old][which]=ch[x][which^1]; f[ ch[old][which] ]=old; ch[x][which^1]=old; f[old]=x; f[x]=oldf; if (oldf) ch[oldf][ ch[oldf][1]==old ]=x; update(old); update(x);}inline void splay(int x,int tar){ for (int fa;(fa=f[x])!=tar;rotate(x)) if (f[fa]!=tar) rotate( (get(x)==get(fa)) ?fa:x ); if (tar==0) root=x;}inline int build(int l,int r,int fa){ if (l>r) return 0; int mid=(l+r)>>1; int now=++sz; key[now]=a[mid]; f[now]=fa; delta[now]=0; int lch=build(l,mid-1,now); int rch=build(mid+1,r,now); ch[now][0]=lch; ch[now][1]=rch; update(now); return now;}inline int find(int x){ int now=root; while (1){ pushdown(now); if (x<=size[ch[now][0]]) now=ch[now][0]; else{ x-=size[ ch[now][0] ]+1; if (!x) return now; now=ch[now][1]; } }}inline void print(int now){ pushdown(now); if (ch[now][0]) print(ch[now][0]); if (key[now]!=-INF&&key[now]!=INF) printf("%d ",key[now]); if (ch[now][1]) print(ch[now][1]);}int main(){ scanf("%d%d",&n,&m); a[1]=-INF; a[n+2]=INF; for (int i=1;i<=n;++i) a[i+1]=i; root=build(1,n+2,0); for (int i=1;i<=m;++i){ scanf("%d%d",&x,&y); int aa=find(x); int bb=find(y+2); splay(aa,0); splay(bb,aa); delta[ ch[ ch[root][1] ][0] ]^=1; } print(root);}
0 1
- [BZOJ3223] 文艺平衡树 - splay
- [BZOJ3223]文艺平衡树 splay
- bzoj3223文艺平衡树splay
- BZOJ3223 文艺平衡树(Splay)
- [BZOJ3223]文艺平衡树(平衡树splay)
- [BZOJ3223]文艺平衡树(平衡树splay)
- 【bzoj3223】文艺平衡树【Splay】【呵呵】
- 【bzoj3223】Tyvj 1729 文艺平衡树 Splay
- 【BZOJ3223】文艺平衡树,Splay反转区间
- bzoj3223 文艺平衡树 Splay & Treap
- 【BZOJ3223】Tyvj 1729 文艺平衡树【Splay】
- splay 新模板 【bzoj3223】 文艺平衡树
- bzoj3223 Tyvj 1729 文艺平衡树 (splay)
- BZOJ3223&3224 文艺&普通平衡树 Splay模板(数组)
- 【bzoj3223】文艺平衡树
- BZOJ3223文艺平衡树
- [bzoj3223]文艺平衡树
- bzoj3223 文艺平衡树
- zookeeper
- Shiro入门3:Shiro主要架构、组件介绍
- 8.1 JavaScript:驾驭网页-DOM
- Offer题5 链表末尾插入&删除指定值&从头到尾打印
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either
- [BZOJ3223]文艺平衡树(平衡树splay)
- Web自动化测试中的接口测试
- armeabi armeabi-v7a mips x86 理解
- HDU 1829 并查集
- 为什么logistic regression要使用sigmoid函数
- iOS _ 复制内容到剪切板
- java写入文本
- Adobe flash player10安装失败的解决方法
- 关于APK签名