[BZOJ2761][JLOI2011]不重复数字(splay)
来源:互联网 发布:淘宝moschino 编辑:程序博客网 时间:2024/06/02 07:31
题目描述
传送门
题解
练习平衡树
代码
#include<iostream>#include<cstring>#include<cstdio>using namespace std;#define N 50005int T,n,x,root,sz;bool flag;int f[N],ch[N][2],key[N];void clear(){ flag=false; root=sz=x=0; memset(f,0,sizeof(f));memset(ch,0,sizeof(ch));memset(key,0,sizeof(key));}int get(int x){ return ch[f[x]][1]==x;}void rotate(int x){ int old=f[x],oldf=f[old],wh=get(x); ch[old][wh]=ch[x][wh^1]; f[ch[old][wh]]=old; ch[x][wh^1]=old; f[old]=x; if (oldf) ch[oldf][ch[oldf][1]==old]=x; f[x]=oldf;}void splay(int x){ for (int fa;fa=f[x];rotate(x)) if (f[fa]) rotate( (get(x)==get(fa))?fa:x ); root=x;}bool insert(int x){ if (!root) { root=++sz; key[sz]=x; return true; } int now=root,fa=0; while (1) { if (x==key[now]) { splay(now); return false; } fa=now; now=ch[now][x>key[now]]; if (!now) { ++sz; f[sz]=fa;ch[fa][x>key[fa]]=sz; key[sz]=x; splay(sz); return true; } }}int main(){ scanf("%d",&T); while (T--) { clear(); scanf("%d",&n); for (int i=1;i<=n;++i) { scanf("%d",&x); if (insert(x)) { if (flag) putchar(' '); printf("%d",x); flag=true; } } putchar('\n'); }}
0 0
- [BZOJ2761][JLOI2011]不重复数字(splay)
- 【bzoj2761】[JLOI2011]不重复数字
- bzoj2761 [JLOI2011]不重复数字
- [BZOJ2761][JLOI2011]不重复数字
- 【JLOI2011】【BZOJ2761】不重复数字
- bzoj2761 [JLOI2011]不重复数字
- 【bzoj2761】【JLOI2011】不重复数字
- bzoj2761 [JLOI2011]不重复数字
- bzoj2761 [JLOI2011]不重复数字
- BZOJ2761: [JLOI2011]不重复数字
- BZOJ2761 [JLOI2011]不重复数字
- 【BZOJ2761】[JLOI2011]不重复数字 STL set
- [BZOJ2761]JLOI2011不重复的数字
- 【bzoj2761】【JLOI2011】【不重复数字】【平衡树】
- 【BZOJ2761】【hash】[JLOI2011]不重复数字 题解
- BZOJ2761 不重复数字
- [BZOJ2761] 不重复数字
- 【JLOI2011】不重复数字
- 459. Repeated Substring Pattern
- Hibenate错误汇总:java.lang.NoClassDefFoundError:
- jxl操作excel 单元格样式,合并单元格,插入图片,超链接
- spring mvc 框架搭建及详解
- 常见性能优化策略的总结
- [BZOJ2761][JLOI2011]不重复数字(splay)
- flask sqlalchemy wtf 使用笔记
- 解决IllegalStateException: Can not perform this action after onSaveInstanceState
- 关于prefrenceactivity和preferencefragment的作用
- 【Gradle】gradle构建加速
- C++primer第4版第八章标准IO库
- JQuery 百度地图
- Exynos 4412 看门狗定时器中断
- 尝试新思路——跨平台Select模型