#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. 【LeetCode-数组篇】 1 Two Sum

    1 前言 之所以开始刷 LeetCode 上的算法题,一是快面临秋招,第二点是因为提升自己的编程能力,坚持两个月,希望博友们监督. 这个系列打算用 C# 和 Java 编程,为什么用两门语言,因为经历 ...

  2. .net core实践系列之短信服务-架构设计

    前言 上篇<.net core实践系列之短信服务-为什么选择.net core(开篇)>简单的介绍了(水了一篇).net core.这次针对短信服务的架构设计和技术栈的简析. 源码地址:h ...

  3. Microsoft Tech Summit 2018 课程简述:利用 Windows 新特性开发出更好的手绘视频应用

    概述 Microsoft Tech Summit 2018 微软技术暨生态大会将于10月24日至27日在上海世博中心举行,这也会是国内举办的最后一届 Tech Summit,2019 年开始会以 Mi ...

  4. 失物找寻APP软件需求规格说明书——第三次团队作业

    ⭐对于软件需求规格说明书的理解 在没写这份软件需求规格说明书的时候我们组成员都不是很理解它的必要性,当然,写完之后才知道它的作用. 软件需求说明书的存在是为了使用户和软件开发者双方对该软件的初始规定有 ...

  5. Django 中间件版登录验证

    中间件版的登录验证需要依靠session,所以数据库中要有django_session表. urls.py # urls.py from django.conf.urls import url fro ...

  6. PySpider框架的基本用法

    pyspider安装: 3.7之后无法正常使用,使用可以下载Python3.6或以下,或者修改pyspider内部代码 ———————————————————————————————————————— ...

  7. Python入门-三级菜单

    作业题目: 三级菜单 作业需求: menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'google':{} }, '中关村':{ '爱奇艺':{}, ...

  8. c#中用sql存储过程

    string connstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionStri ...

  9. Python里面如何拷贝一个对象

    1.赋值(=),就是创建了对象的一个新的引用,修改其中任意一个变量都会影响到另一个. In [168]: a Out[168]: [1, 2, 3] In [169]: b=a In [170]: a ...

  10. anaconda 出现add 。。。进不去

    找到.condarc 文件  C:\Users\leiyi内 把里面内容替换为 channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pk ...