#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. @Vue/Cli 3 Invalid Host header 检测关闭

    Invalid Host header 在本地开发等一般情况下,无论是 local,还是 ip,或者是 0.0.0.0,在 cli 中都默认为合法的,但是有些场景可能会被不支持,比如远程开发,或者是云 ...

  2. 朱晔和你聊Spring系列S1E1:聊聊Spring家族的几大件

    朱晔和你聊Spring系列S1E1:聊聊Spring家族的几大件 [下载本文PDF进行阅读] Spring家族很庞大,从最早先出现的服务于企业级程序开发的Core.安全方面的Security.到后来的 ...

  3. 朱晔的互联网架构实践心得S1E6:给飞机换引擎和安全意识十原则

    朱晔的互联网架构实践心得S1E6:给飞机换引擎和安全意识十原则 [下载本文PDF进行阅读] 本文有两个部分,先介绍一下给飞机换引擎这个事情我的一些经验,因为篇幅较短然后介绍一下安全意识方面的一些心得. ...

  4. Sparse Principal Component Analysis via Rotation and Truncation

    目录 对以往一些SPCA算法复杂度的总结 Notation 论文概述 原始问题 问题的变种 算法 固定\(X\),计算\(R\) 固定\(R\),求解\(X\) (\(Z =VR^{\mathrm{T ...

  5. Misha, Grisha and Underground CodeForces - 832D (倍增树上求LCA)

    Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations ...

  6. 利用tushare进行对兴业银行股价的爬取,并使用numpy进行分析

    import sysimport tushare as tsimport numpy as npdata=ts.get_h_data('601066')print(data)#读出兴业银行7列数据da ...

  7. iOS Keychain,SSKeychain,使用 理解 原理

    https://www.cnblogs.com/m4abcd/p/5242254.html Keychain 使用? ---为了实用最大化我觉得我应该直接先说使用! 当然是使用第三方库啦:sskeyc ...

  8. vmware can not be closed virtual machine is busy

    VMware does not close when Windows Server 2003 ... |VMware Communities https://communities.vmware.co ...

  9. 图片转字符画 【学习ing】

    1.创建ascii.py 2. 下面是 ascii.py 的完整代码: from PIL import Image import argparse #命令行输入参数处理 parser = argpar ...

  10. js原生实现div渐入渐出

    jq对渐入渐出进行封装,简单的使用连个方法就可以实现.fadeIn(),fadeOut();如果我们界面没有使用jq那么原生怎么实现呢? 我们讲解一下,这个原理.当我们要实现渐入的时候,首先是让隐藏的 ...