查最小值,删除,翻转。。。

显然splay啊。。。

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #define N 200005
  6. #define inf 0x3f3f3f3f
  7. using namespace std;
  8. int n;
  9. int ch[N][], fa[N];
  10. int a[N];
  11. int mn[N],zhi[N],size[N];
  12. void push_up(int x)
  13. {
  14. size[x] = size[ch[x][]] + size[ch[x][]] + ;
  15. mn[x] = min(zhi[x], min(mn[ch[x][]], mn[ch[x][]])); return;
  16. }
  17. int rev[N];
  18. void push_down(int x)
  19. {
  20. if (rev[x])
  21. {
  22. rev[x] ^= ; rev[ch[x][]] ^= ; rev[ch[x][]] ^= ;
  23. swap(ch[x][], ch[x][]);
  24. }
  25. return;
  26. }
  27. void rotate(int p)
  28. {
  29. int q = fa[p], y = fa[q], x = (ch[q][] == p);
  30. ch[q][x] = ch[p][x ^ ]; fa[ch[q][x]] = q;
  31. ch[p][x ^ ] = q; fa[q] = p;
  32. fa[p] = y;
  33. if (y)
  34. {
  35. if (ch[y][] == q)ch[y][] = p;
  36. else ch[y][] = p;
  37. }
  38. push_up(q); return;
  39. }
  40. int root;
  41. void splay(int x,int yy)
  42. {
  43. for (int y; y = fa[x]; rotate(x))
  44. {
  45. if (y == yy)break;
  46. if (fa[y] != yy)
  47. {
  48. if ((ch[fa[y]][] == y) ^ (ch[y][] == x))rotate(x);
  49. else rotate(y);
  50. }
  51. }
  52. push_up(x);
  53. if (!yy)root = x;
  54. }
  55. int cnt;
  56. int find(int k, int x)
  57. {
  58. push_down(k);
  59. if (mn[ch[k][]] == x)
  60. {
  61. return find(ch[k][], x);
  62. }
  63. if (zhi[k] == x)return size[ch[k][]] + ;
  64. return find(ch[k][], x) + size[ch[k][]] + ;
  65. }
  66. int fd(int k, int x)
  67. {
  68. push_down(k);
  69. if (size[ch[k][]] + == x)return k;
  70. if (size[ch[k][]] + >= x)return fd(ch[k][],x);
  71. return fd(ch[k][], x - size[ch[k][]] - );
  72. }
  73. struct node
  74. {
  75. int yuan,z;
  76. friend bool operator < (node aa,node bb)
  77. {
  78. if(aa.z!=bb.z)return aa.z<bb.z;
  79. return aa.yuan<bb.yuan;
  80. }
  81. }s[N];
  82. int yin[N];
  83. int main()
  84. {
  85. scanf("%d", &n); mn[] = inf;
  86. for (int i = ; i <= n; i++)
  87. {
  88. s[i].yuan=i;scanf("%d",&s[i].z);
  89. }
  90. sort(s+,s+n+);
  91. for(int i=;i<=n;i++)
  92. {
  93. a[s[i].yuan]=i;
  94. }
  95. root = ; a[n + ] = inf;
  96. ch[][] = ; zhi[] = a[]; size[] = n + ;
  97. for (int i = ; i <= n + ; i++)
  98. {
  99. size[i] = n - i + ;
  100. zhi[i] = a[i]; fa[i] = i - ; ch[i - ][] = i;
  101. }
  102. for (int i = n + ; i >= ; i--)push_up(i);
  103. splay(n, );
  104. for (int i = ; i <= n; i++)
  105. {
  106. int y = find(root, mn[root]);
  107. if(i!=n)printf("%d ",y+(i-));
  108. else printf("%d",y+(i-));
  109. int t = fd(root, y+);
  110. splay(t, );
  111. rev[ch[t][]] ^= ;
  112. t = fd(root, );
  113. splay(t, );
  114. ch[t][] = ;
  115. push_up(t);
  116. }
  117. puts("");
  118. return ;
  119. }

bzoj 3506 && bzoj 1552 splay的更多相关文章

  1. 【BZOJ】【1552】【Cerc2007】robotic sort / 【3506】【CQOI2014】排序机械臂

    Splay 离散化+Splay维护序列…… 好吧主要说一下我做这道题遇到的几个错误点: 1.离散化 2.由于找到的这个数的位置一定是大于等于 i 的,所以其实在把它splay到根以后,i 结点只能sp ...

  2. [题解]bzoj 1861 Book 书架 - Splay

    1861: [Zjoi2006]Book 书架 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 1396  Solved: 803[Submit][Stat ...

  3. bzoj 3223 文艺平衡树 - Splay

    3223: Tyvj 1729 文艺平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3884  Solved: 2235[Submit][Sta ...

  4. bzoj 1269 bzoj 1507 Splay处理文本信息

    bzoj 1269 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1269 大致思路: 用splay维护整个文本信息,splay树的中序遍历即为 ...

  5. BZOJ 1251: 序列终结者 [splay]

    1251: 序列终结者 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 3778  Solved: 1583[Submit][Status][Discu ...

  6. BZOJ 1588 营业额统计 Splay

    主要操作为Splay中插入节点,查找前驱和后继节点. 1: #include <cstdio> 2: #include <iostream> 3: #include <c ...

  7. BZOJ 1269 文本编辑器 Splay

    题目大意:维护一个文本编辑器,支持下列操作: 1.将光标移动到某一位置 2.在光标后插入一段字符串 3.删除光标后的一段字符 4.翻转光标后的一段字符 5.输出光标后的一个字符 6.光标-- 7.光标 ...

  8. [BZOJ 1500]维修数列 [Splay Tree从进阶到住院]

    历尽艰辛终于A掉了这题QwQ 贴COGS评论区几句话=.= 策爷:"splay/块状链表的自虐题.".深刻理解到如果没有M倾向就不要去写这题了.. -Chenyao2333 记得b ...

  9. BZOJ 3545: [ONTAK2010]Peaks [Splay启发式合并]

    3545: [ONTAK2010]Peaks 题意:带权图,多组询问与一个点通过边权\(\le x\)的边连通的点中点权k大值 又读错题了,输出点一直WA,问的是点权啊 本题加强版强制在线了,那这道题 ...

随机推荐

  1. 《.NET开发资源大全》

    目录 API 应用框架(Application Frameworks) 应用模板(Application Templates) 人工智能(Artificial Intelligence) 程序集处理( ...

  2. 关于css3的背景渐变

    关于css3的渐变,目前各大浏览器还未做到很好的支持,所以需要在我们使用时加上各大浏览器前缀. -moz-:使用Mozilla内核的浏览器(Firefox浏览器) -webkit-:使用Webkit内 ...

  3. Bootstrap之选项卡

    <div class="container"> <!-- nav-tabs作为选项卡头部样式 --> <ul class="nav nav- ...

  4. Sharepoint2013 AD组用户不同步

    背景: SP2013列表库使用AD安全组授权访问,向AD安全组添加一个用户A,在Sharepoint AD同步(增量和完全)后,用户A仍然无法访问列表库:原因: 参考:安全令牌上的缓存  SP2013 ...

  5. 调用sharepoint 2010 REST报版本过低

    问题描述: 写了一个webservice调用sharepoint REST,本机测试成功,部署到服务器上后报错 (System.Data.Services.Client.DataServiceQuer ...

  6. Linux Distribution / ROM

    Linux发行版 http://unix.stackexchange.com/questions/87011/how-to-easily-build-your-own-linux-distro 这个文 ...

  7. [Android]使用Dagger 2依赖注入 - 自定义Scope(翻译)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5095426.html 使用Dagger 2依赖注入 - 自定义 ...

  8. ButterKnife Zelezny从配置到使用

    插件介绍:ButterKnife是一个专注于Android系统的View注入框架,可以减少大量的findViewById以及setOnClickListener代码,可视化一键生成.又一神器,完美告别 ...

  9. [Erlang 0116] 当我们谈论Erlang Maps时,我们谈论什么 Part 1

         Erlang 增加 Maps数据类型并不是很突然,因为这个提议已经进行了2~3年之久,只不过Joe Armstrong老爷子最近一篇文章Big changes to Erlang掀起不小了风 ...

  10. 在阿里云中编译Linux4.5.0内核 - Ubuntu内核编译教程

    实验环境:Ubnuntu 64位(推荐使用14.04)+Xshell 阿里云现在提供的云服务器很好用的,用来编译内核性能也不错.本文介绍最基本的内核编译方法,为了方便,所有操作均在root用户下进行. ...