1552/3506. [CQOI2014]排序机械臂【平衡树-splay】
Description

Input
Output
Sample Input
3 4 5 1 6 2
Sample Output
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N (100000+100)
using namespace std;
struct node
{
int id,num;
} b[N];
int Key[N],Rev[N],Size[N];
int Father[N],Son[N][];
int n,Root,a[N],Rank[N]; bool cmp(node a,node b)
{
return a.num==b.num?a.id<b.id:a.num<b.num;
}
inline int Get(int x)
{
return Son[Father[x]][]==x;
} inline void Update(int x)
{
Size[x]=Size[Son[x][]]+Size[Son[x][]]+;
} inline void Pushdown(int x)
{
if (Rev[x])
{
Rev[x]=;
swap(Son[x][],Son[x][]);
Rev[Son[x][]]^=;
Rev[Son[x][]]^=;
}
} inline void Rotate(int x)
{
Pushdown(Father[x]);
Pushdown(x);
int wh=Get(x);
int fa=Father[x],fafa=Father[fa];
Son[fa][wh]=Son[x][wh^];
Father[fa]=x;
if (Son[fa][wh]) Father[Son[fa][wh]]=fa;
Son[x][wh^]=fa;
Father[x]=fafa;
if (fafa) Son[fafa][Son[fafa][]==fa]=x;
Update(fa);
Update(x);
} inline void Splay(int x,int tar)
{
for (int fa;(fa=Father[x])!=tar;Rotate(x))
if (Father[fa]!=tar)
Rotate(Get(fa)==Get(x)?fa:x);
if (!tar) Root=x;
} void Build(int l,int r,int fa)
{
if (l>r) return;
if (l==r)
{
Size[l]=;
Father[l]=fa;
Son[fa][l>fa]=l;
return;
}
int mid=(l+r)>>;
Build(l,mid-,mid);
Build(mid+,r,mid);
Father[mid]=fa;
Son[fa][mid>fa]=mid;
Update(mid);
} int Findx(int x)
{
int now=Root;
while ()
{
Pushdown(now);
if (Size[Son[now][]]>=x)
now=Son[now][];
else
{
x-=Size[Son[now][]];
if (x==)
{
Splay(now,);
return now;
}
x--;
now=Son[now][];
}
}
} inline int Split(int x,int y)
{
int xx=Findx(x),yy=Findx(y);
Splay(xx,);
Splay(yy,xx);
return Son[yy][];
} int main()
{
scanf("%d",&n);
for (int i=; i<=n; ++i)
{
scanf("%d",&a[i+]);
b[i].id=i+;
b[i].num=a[i+];
}
sort(b+,b+n+,cmp);
for (int i=; i<=n; ++i)
Rank[i]=b[i].id;
Build(,n+,);
Root=(n+)/;
for (int i=; i<=n; ++i)
{
Splay(Rank[i],);
int ans=Size[Son[Root][]]+;
printf("%d ",ans-);
int hh=Split(i,ans+);
Rev[hh]^=;
}
}
1552/3506. [CQOI2014]排序机械臂【平衡树-splay】的更多相关文章
- 【BZOJ3506】[CQOI2014] 排序机械臂(Splay)
点此看题面 大致题意: 给你\(n\)个数.第一次找到最小值所在位置\(P_1\),翻转\([1,P_1]\),第二次找到剩余数中最小值所在位置\(P_2\),翻转\([2,P_2]\),以此类推.求 ...
- 【洛谷 P3165】 [CQOI2014]排序机械臂 (Splay)
题目链接 debug了\(N\)天没debug出来,原来是找后继的时候没有pushdown... 众所周知,,Splay中每个编号对应的节点的值是永远不会变的,因为所有旋转.翻转操作改变的都是父节点和 ...
- 【BZOJ3506】排序机械臂(Splay)
[BZOJ3506]排序机械臂(Splay) 题面 神TMBZOJ没有题面,感谢SYC的题面 洛谷的题面也不错 题解 对于每次旋转的物体 显然可以预处理出来 现在只要模拟旋转操作就行了 至于在哪里放标 ...
- P3165 [CQOI2014]排序机械臂
题目描述 为了把工厂中高低不等的物品按从低到高排好序,工程师发明了一种排序机械臂.它遵循一个简单的排序规则,第一次操作找到高度最低的物品的位置 P1P_1P1 ,并把左起第一个物品至 P1P_1P1 ...
- 洛谷P3165 [CQOI2014]排序机械臂
题目描述 为了把工厂中高低不等的物品按从低到高排好序,工程师发明了一种排序机械臂.它遵循一个简单的排序规则,第一次操作找到摄低的物品的位置P1,并把左起第一个至P1间的物品反序:第二次找到第二低的物品 ...
- [BZOJ3506] [Cqoi2014] 排序机械臂 (splay)
Description 同OJ1552 Input Output Sample Input Sample Output HINT Source Solution Q:哎不是同一道题吗为什么分两篇博客来 ...
- 洛谷P3165 [CQOI2014]排序机械臂 Splay维护区间最小值
可以将高度定义为小数,这样就完美的解决了优先级的问题. Code: #include<cstdio> #include<algorithm> #include<cstri ...
- Luogu P3165 [CQOI2014]排序机械臂
先讲一下和这题一起四倍经验的题: Luogu P4402 [Cerc2007]robotic sort 机械排序 SP2059 CERC07S - Robotic Sort UVA1402 Robot ...
- BZOJ3506/1502 [CQOI2014]排序机械臂
传送门 依然是一道splay的区间操作,需要注意的是要把下标离散化后来表示splay的节点,我不知道怎么搞所以索性弄了个$ValuetoNode$,看样子没什么问题, 感觉他那个传下标的方法太暴力了. ...
随机推荐
- K:跳表
跳表(SkipList)是一种随机化的数据结构,目前在redis和leveldb中都有用到它,它的效率和红黑树以及 AVL 树不相上下,但跳表的原理相当简单,只要你能熟练操作链表, 就能轻松实现一 ...
- 从敲入 URL 到浏览器渲染完成、对HTTP协议的理解
1. 大致过程 当你这样子回答的时候: 用户输入 url 地址,浏览器查询 DNS 查找对应的请求 IP 地址 建立 TCP 连接 浏览器向服务器发送 http 请求,如果服务器段返回以 301 之类 ...
- PHP的new self() 与new static()
参考链接:[PHP中new static()与new self()的区别异同分析],[PHP中new self()和new static()的区别探究],[PHP中static和self的区别] 要点 ...
- 初学PS
PS中的一些快捷键:新建:Ctrl+N 放大:Ctrl++ 缩小:Ctrl+- 首选项:Ctrl+K 标尺:Ctrl+R移动视图:空格键 绘制正圆:Shift 绘制鼠标落脚点为中心的正圆:Shift+ ...
- Modify Dokuwiki Email Template 修改 Dokuwiki 邮件模板
Email Notification Templates There are two places to modify 1) log in as Admin -> configuration ...
- the interconversion of String and StringBuilder
package com.itheima_03; /* * StringBuilder和String的相互转换 * * StringBuilder -- String * public String t ...
- vmware centos 安装
一.分区 一块硬盘主分区+扩展分区最多只能有4个,其中扩展分区最多只能有1个.扩展分区不能写入数据,只能包含逻辑分区.这些都不是linux的限制,而是硬盘结构的限制. 分区号 第一种分区法: |--- ...
- mybatis resultMap 映射配置
现有数据库表: CREATE TABLE `dept_p` ( `DEPT_ID` ) NOT NULL, `DEPT_NAME` ) DEFAULT NULL, `PARENT_ID` ) DEFA ...
- clr_zmq Vs2010版本
.net的消息队列很方便的一个库. 在github上的主版本虽然也支持fw4.0,但是必须使用vs2012以上进行编译. 这样就依赖vcredist运行时. 因为win7 sp1以下版本,无法安装vc ...
- zabbix系列之一——简要介绍
参考来源:(官网) https://www.zabbix.com/documentation/3.4/manual/introduction/about 1what’s zabbix? index d ...