#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std; #define Key_value (ch[ch[root][1] ][0]) const int maxn = 2e5+;
const int INF = 0x3f3f3f3f; int pre[maxn],ch[maxn][],key[maxn],size[maxn];
int root,tot1;
int rev[maxn];
int s[maxn],tot2;
int N; struct Node{
int num,id;
bool operator < (const Node &rhs) const
{
if(num == rhs.num) return id < rhs.id;
else return num < rhs.num;
}
}node[maxn]; void Treavel(int x)
{
if(x)
{
Treavel(ch[x][]);
printf("结点:%2d: 左儿子 %2d 右儿子 %2d 父结点 %2d size= %2d val=%2d\n",x,ch[x][],ch[x][],pre[x],size[x],key[x]);
Treavel(ch[x][]);
}
} void debug()
{
printf("root:%d\n",root);
Treavel(root);
} void NewNode(int &o,int father,int k)
{
o = k;
pre[o] = father;
ch[o][] = ch[o][] = ;
rev[o] = ;
size[o] = ;
}
void update_rev(int o)
{
if(!o) return ;
swap(ch[o][],ch[o][]);
rev[o] ^= ;
}
void push_up(int o)
{
int lson = ch[o][],rson = ch[o][];
size[o] = size[lson]+size[rson] + ;
}
void push_down(int o)
{
if(rev[o])
{
update_rev(ch[o][]);
update_rev(ch[o][]);
rev[o] = ;
}
}
void Build(int &x,int l,int r,int father)
{
if(l > r) return ;
int mid = (l+r)>>;
NewNode(x,father,mid);
Build(ch[x][],l,mid-,x);
Build(ch[x][],mid+,r,x);
push_up(x);
}
void Init()
{
root = tot1 = tot2 = ;
ch[root][] = ch[root][] = size[root] = pre[root] = ;
rev[root] = ;
NewNode(root,,N+);
NewNode(ch[root][],root,N+); Build(Key_value,,N,ch[root][]);
push_up(ch[root][]);
push_up(root);
}
void Rotate(int x,int kind)
{
int y = pre[x];
push_down(y);
push_down(x);
ch[y][!kind] = ch[x][kind];
pre[ch[x][kind] ] = y;
if(pre[y])
ch[pre[y] ][ch[pre[y]][]==y ] = x;
pre[x] = pre[y];
ch[x][kind] = y;
pre[y] = x;
push_up(y);
}
void Splay(int x,int goal)
{
push_down(x);
while(pre[x] != goal)
{
if(pre[pre[x] ] == goal)
{
push_down(pre[x]);
push_down(x);
Rotate(x,ch[pre[x]][]==x);
}
else
{
push_down(pre[pre[x] ]);
push_down(pre[x]);
push_down(x);
int y = pre[x];
int kind = ch[pre[y] ][] == y;
if(ch[y][kind] == x)
{
Rotate(x,!kind);
Rotate(x,kind);
}
else
{
Rotate(y,kind);
Rotate(x,kind);
}
}
}
push_up(x);
if(goal == ) root = x;
}
int Get_kth(int x,int k)
{
push_down(x);
int t = size[ch[x][]] + ;
if(t==k) return x;
if(t > k) return Get_kth(ch[x][],k);
else return Get_kth(ch[x][],k-t);
}
int Get_next(int x)
{
push_down(x);
if(ch[x][] == ) return -;
x = ch[x][];
while(ch[x][])
{
x = ch[x][];
push_down(x);
}
return x;
}
int main()
{
while(scanf("%d",&N) && N)
{
for(int i=;i<=N;i++)
{
scanf("%d",&node[i].num);
node[i].id = i;
}
sort(node+,node+N+);
Init();
for(int i=;i<=N;i++)
{
Splay(node[i].id,);
printf("%d%s",size[ch[root][]],i==N?"":" ");
Splay(Get_kth(root,i),);
Splay(Get_next(node[i].id),root);
update_rev(Key_value);
}
printf("\n");
}
}

HDU1890-Robotic Sort-Splay的更多相关文章

  1. HDU1890 Robotic Sort[splay 序列]

    Robotic Sort Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. HDU1890 Robotic Sort Splay tree反转,删除

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1890 题目中涉及数的反转和删除操作,需要用Splay tree来实现.首先对数列排序,得到每个数在数列 ...

  3. hdu1890 Robotic Sort (splay+区间翻转单点更新)

    Problem Description Somewhere deep in the Czech Technical University buildings, there are laboratori ...

  4. HDU 1890 Robotic Sort | Splay

    Robotic Sort Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [Pr ...

  5. BZOJ 1552: [Cerc2007]robotic sort( splay )

    kpm大神说可以用块状链表写...但是我不会...写了个splay.... 先离散化 , 然后splay结点加个min维护最小值 , 就可以了... ( ps BZOJ 3506 题意一样 , 双倍经 ...

  6. hdu 1890 Robotic Sort(splay 区间反转+删点)

    题目链接:hdu 1890 Robotic Sort 题意: 给你n个数,每次找到第i小的数的位置,然后输出这个位置,然后将这个位置前面的数翻转一下,然后删除这个数,这样执行n次. 题解: 典型的sp ...

  7. 【BZOJ1552】[Cerc2007]robotic sort Splay

    [BZOJ1552][Cerc2007]robotic sort Description Input 输入共两行,第一行为一个整数N,N表示物品的个数,1<=N<=100000.第二行为N ...

  8. 【bzoj1552/3506】[Cerc2007]robotic sort splay翻转,区间最值

    [bzoj1552/3506][Cerc2007]robotic sort Description Input 输入共两行,第一行为一个整数N,N表示物品的个数,1<=N<=100000. ...

  9. [BZOJ1552] [Cerc2007] robotic sort (splay)

    Description Input 输入共两行,第一行为一个整数N,N表示物品的个数,1<=N<=100000.第二行为N个用空格隔开的正整数,表示N个物品最初排列的编号. Output ...

  10. HDU 1890 - Robotic Sort - [splay][区间反转+删除根节点]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1890 Time Limit: 6000/2000 MS (Java/Others) Memory Li ...

随机推荐

  1. Java 多线程(六)之Java内存模型

    目录 1. 并发编程的两个问题 2 CPU 缓存模型 2.1 CPU 和 主存 2.2 CPU Cache 2.3 CPU如何通过 Cache 与 主内存交互 2.4 CPU 缓存一致性问题 3 Ja ...

  2. 前端面试送命题(二)-callback,promise,generator,async-await

    前言 本篇文章适合前端架构师,或者进阶的前端开发人员:我在面试vmware前端架构师的时候,被问到关于callback,promise,generator,async-await的问题. 首先我们回顾 ...

  3. .NET Core Community 第二个千星项目诞生:Util

    本文所有打赏将全数捐赠于 NCC(NCC 的资金目前由 倾竹大人 负责管理),请注明捐赠于 NCC.捐赠情况将由倾竹大人另行公示. 项目简介 作为一款旨在提升小型团队开发输出能力.提高团队效率.降低项 ...

  4. mysql自增id超大问题查询

    引言 小A正在balabala写代码呢,DBA小B突然发来了一条消息,"快看看你的用户特定信息表T,里面的主键,也就是自增id,都到16亿了,这才多久,在这样下去过不了多久主键就要超出范围了 ...

  5. H5 类选择器

    10-类选择器 错误的写法: --> 迟到毁一生 早退穷三代 按时上下班 必成高富帅 我是段落 我是段落 <!DOCTYPE html> <html lang="en ...

  6. Python-类的特性(property)

    什么是特性property property是一种特殊的属性,访问它时会执行一段功能(函数)然后返回值 例一:BMI指数(bmi是计算而来的,但很明显它听起来像是一个属性而非方法,如果我们将其做成一个 ...

  7. Makes And The Product CodeForces - 817B (思维+构造)

    B. Makes And The Product time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. centos开启ftp服务的步骤

    1.安装vsftpd sudo yum install vsftpd -y 2.启动ftp服务 service vsftpd start 3.  加入开机启动 chkconfig vsftpd on ...

  9. .net之httphandler小记

    本地调试代码遇到的一个问题,没有走URL路由器(UrlReWriter : IHttpHandlerFactory),于是网上科普了一下原理,主要有两点: 1.asp.net在处理http请求时,会由 ...

  10. (Git 学习)Git SSH Key 创建步骤

    首先感谢segmentfalut上的朋友对我帮助. 首先:查看你是否有../ssh 这个文件:怎么查看:找到你的git安装目录,在安装目录下查看是否./ssh,以我的为例: 在C盘/Users/11/ ...