bzoj 3506 && bzoj 1552 splay
查最小值,删除,翻转。。。
显然splay啊。。。
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- #define N 200005
- #define inf 0x3f3f3f3f
- using namespace std;
- int n;
- int ch[N][], fa[N];
- int a[N];
- int mn[N],zhi[N],size[N];
- void push_up(int x)
- {
- size[x] = size[ch[x][]] + size[ch[x][]] + ;
- mn[x] = min(zhi[x], min(mn[ch[x][]], mn[ch[x][]])); return;
- }
- int rev[N];
- void push_down(int x)
- {
- if (rev[x])
- {
- rev[x] ^= ; rev[ch[x][]] ^= ; rev[ch[x][]] ^= ;
- swap(ch[x][], ch[x][]);
- }
- return;
- }
- void rotate(int p)
- {
- int q = fa[p], y = fa[q], x = (ch[q][] == p);
- ch[q][x] = ch[p][x ^ ]; fa[ch[q][x]] = q;
- ch[p][x ^ ] = q; fa[q] = p;
- fa[p] = y;
- if (y)
- {
- if (ch[y][] == q)ch[y][] = p;
- else ch[y][] = p;
- }
- push_up(q); return;
- }
- int root;
- void splay(int x,int yy)
- {
- for (int y; y = fa[x]; rotate(x))
- {
- if (y == yy)break;
- if (fa[y] != yy)
- {
- if ((ch[fa[y]][] == y) ^ (ch[y][] == x))rotate(x);
- else rotate(y);
- }
- }
- push_up(x);
- if (!yy)root = x;
- }
- int cnt;
- int find(int k, int x)
- {
- push_down(k);
- if (mn[ch[k][]] == x)
- {
- return find(ch[k][], x);
- }
- if (zhi[k] == x)return size[ch[k][]] + ;
- return find(ch[k][], x) + size[ch[k][]] + ;
- }
- int fd(int k, int x)
- {
- push_down(k);
- if (size[ch[k][]] + == x)return k;
- if (size[ch[k][]] + >= x)return fd(ch[k][],x);
- return fd(ch[k][], x - size[ch[k][]] - );
- }
- struct node
- {
- int yuan,z;
- friend bool operator < (node aa,node bb)
- {
- if(aa.z!=bb.z)return aa.z<bb.z;
- return aa.yuan<bb.yuan;
- }
- }s[N];
- int yin[N];
- int main()
- {
- scanf("%d", &n); mn[] = inf;
- for (int i = ; i <= n; i++)
- {
- s[i].yuan=i;scanf("%d",&s[i].z);
- }
- sort(s+,s+n+);
- for(int i=;i<=n;i++)
- {
- a[s[i].yuan]=i;
- }
- root = ; a[n + ] = inf;
- ch[][] = ; zhi[] = a[]; size[] = n + ;
- for (int i = ; i <= n + ; i++)
- {
- size[i] = n - i + ;
- zhi[i] = a[i]; fa[i] = i - ; ch[i - ][] = i;
- }
- for (int i = n + ; i >= ; i--)push_up(i);
- splay(n, );
- for (int i = ; i <= n; i++)
- {
- int y = find(root, mn[root]);
- if(i!=n)printf("%d ",y+(i-));
- else printf("%d",y+(i-));
- int t = fd(root, y+);
- splay(t, );
- rev[ch[t][]] ^= ;
- t = fd(root, );
- splay(t, );
- ch[t][] = ;
- push_up(t);
- }
- puts("");
- return ;
- }
bzoj 3506 && bzoj 1552 splay的更多相关文章
- 【BZOJ】【1552】【Cerc2007】robotic sort / 【3506】【CQOI2014】排序机械臂
Splay 离散化+Splay维护序列…… 好吧主要说一下我做这道题遇到的几个错误点: 1.离散化 2.由于找到的这个数的位置一定是大于等于 i 的,所以其实在把它splay到根以后,i 结点只能sp ...
- [题解]bzoj 1861 Book 书架 - Splay
1861: [Zjoi2006]Book 书架 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 1396 Solved: 803[Submit][Stat ...
- bzoj 3223 文艺平衡树 - Splay
3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3884 Solved: 2235[Submit][Sta ...
- bzoj 1269 bzoj 1507 Splay处理文本信息
bzoj 1269 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1269 大致思路: 用splay维护整个文本信息,splay树的中序遍历即为 ...
- BZOJ 1251: 序列终结者 [splay]
1251: 序列终结者 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 3778 Solved: 1583[Submit][Status][Discu ...
- BZOJ 1588 营业额统计 Splay
主要操作为Splay中插入节点,查找前驱和后继节点. 1: #include <cstdio> 2: #include <iostream> 3: #include <c ...
- BZOJ 1269 文本编辑器 Splay
题目大意:维护一个文本编辑器,支持下列操作: 1.将光标移动到某一位置 2.在光标后插入一段字符串 3.删除光标后的一段字符 4.翻转光标后的一段字符 5.输出光标后的一个字符 6.光标-- 7.光标 ...
- [BZOJ 1500]维修数列 [Splay Tree从进阶到住院]
历尽艰辛终于A掉了这题QwQ 贴COGS评论区几句话=.= 策爷:"splay/块状链表的自虐题.".深刻理解到如果没有M倾向就不要去写这题了.. -Chenyao2333 记得b ...
- BZOJ 3545: [ONTAK2010]Peaks [Splay启发式合并]
3545: [ONTAK2010]Peaks 题意:带权图,多组询问与一个点通过边权\(\le x\)的边连通的点中点权k大值 又读错题了,输出点一直WA,问的是点权啊 本题加强版强制在线了,那这道题 ...
随机推荐
- 《.NET开发资源大全》
目录 API 应用框架(Application Frameworks) 应用模板(Application Templates) 人工智能(Artificial Intelligence) 程序集处理( ...
- 关于css3的背景渐变
关于css3的渐变,目前各大浏览器还未做到很好的支持,所以需要在我们使用时加上各大浏览器前缀. -moz-:使用Mozilla内核的浏览器(Firefox浏览器) -webkit-:使用Webkit内 ...
- Bootstrap之选项卡
<div class="container"> <!-- nav-tabs作为选项卡头部样式 --> <ul class="nav nav- ...
- Sharepoint2013 AD组用户不同步
背景: SP2013列表库使用AD安全组授权访问,向AD安全组添加一个用户A,在Sharepoint AD同步(增量和完全)后,用户A仍然无法访问列表库:原因: 参考:安全令牌上的缓存 SP2013 ...
- 调用sharepoint 2010 REST报版本过低
问题描述: 写了一个webservice调用sharepoint REST,本机测试成功,部署到服务器上后报错 (System.Data.Services.Client.DataServiceQuer ...
- Linux Distribution / ROM
Linux发行版 http://unix.stackexchange.com/questions/87011/how-to-easily-build-your-own-linux-distro 这个文 ...
- [Android]使用Dagger 2依赖注入 - 自定义Scope(翻译)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5095426.html 使用Dagger 2依赖注入 - 自定义 ...
- ButterKnife Zelezny从配置到使用
插件介绍:ButterKnife是一个专注于Android系统的View注入框架,可以减少大量的findViewById以及setOnClickListener代码,可视化一键生成.又一神器,完美告别 ...
- [Erlang 0116] 当我们谈论Erlang Maps时,我们谈论什么 Part 1
Erlang 增加 Maps数据类型并不是很突然,因为这个提议已经进行了2~3年之久,只不过Joe Armstrong老爷子最近一篇文章Big changes to Erlang掀起不小了风 ...
- 在阿里云中编译Linux4.5.0内核 - Ubuntu内核编译教程
实验环境:Ubnuntu 64位(推荐使用14.04)+Xshell 阿里云现在提供的云服务器很好用的,用来编译内核性能也不错.本文介绍最基本的内核编译方法,为了方便,所有操作均在root用户下进行. ...