具体是啥,qwq

有时间再补吧,贴一下代码;

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<cstring>
  6. #define MAXN 10086666
  7. using namespace std;
  8. int f[MAXN],cnt[MAXN],value[MAXN];
  9. int sons[MAXN][],sub_size[MAXN];
  10. int root,whole_size;
  11. int m,num,be_dealt;
  12. inline int read()
  13. {
  14. int x = ;
  15. int f = ;
  16. char ch = getchar();
  17. while(!isdigit(ch))
  18. {
  19. if(ch == '-')
  20. f = -;
  21. ch = getchar();
  22. }
  23. while(isdigit(ch))
  24. {
  25. x = x * + ch - ;
  26. ch = getchar();
  27. }
  28. return x * f;
  29. }
  30. inline void S_clear(int x)
  31. {
  32. sons[x][] = sons[x][] = ;
  33. f[x] = cnt[x] = value[x] = ;
  34. sub_size[x] = ;
  35. }
  36. inline bool get_which(int x)
  37. {
  38. return sons[f[x]][] == x;
  39. }
  40. inline void update(int x)
  41. {
  42. if(x)
  43. {
  44. sub_size[x] = cnt[x];
  45. if(sons[x][])
  46. sub_size[x] += sub_size[sons[x][]];
  47. if(sons[x][])
  48. sub_size[x] += sub_size[sons[x][]];
  49. }
  50. return ;
  51. }
  52. inline void rotate(int x)
  53. {
  54. int father = f[x];
  55. int g_father = f[father];
  56. int which_son = get_which(x);
  57. sons[father][which_son] = sons[x][which_son ^ ];
  58. f[sons[father][which_son]] = father;
  59. sons[x][which_son ^ ] = father;
  60. f[father] = x;
  61. f[x] = g_father;
  62. if(g_father)
  63. sons[g_father][sons[g_father][] == father] = x;
  64. update(father);
  65. update(x);
  66. }
  67. inline void splay(int x)
  68. {
  69. for(int fa;fa = f[x];rotate(x))
  70. if(f[fa])
  71. rotate((get_which(x)) == get_which(fa) ? fa : x);
  72. root = x;
  73. }
  74. inline void insert(int x)
  75. {
  76. if(!root)
  77. {
  78. whole_size++;
  79. sons[whole_size][] = sons[whole_size][] = f[whole_size] = ;
  80. root = whole_size;
  81. sub_size[whole_size] = cnt[whole_size]++;
  82. value[whole_size] = x;
  83. return ;
  84. }
  85. int now = root;
  86. int fa = ;
  87. while()
  88. {
  89. if(x == value[now])
  90. {
  91. cnt[now]++;
  92. update(now);
  93. update(fa);
  94. splay(now);
  95. break;
  96. }
  97. fa = now;
  98. now = sons[now][value[now] < x];
  99. if(!now)
  100. {
  101. whole_size++;
  102. sons[whole_size][] = sons[whole_size][] = ;
  103. f[whole_size] = fa;
  104. sub_size[whole_size] = cnt[whole_size] = ;
  105. sons[fa][value[fa] < x] = whole_size;
  106. value[whole_size] = x;
  107. update(fa);
  108. splay(whole_size);
  109. break;
  110. }
  111. }
  112. }
  113. inline int find_sum(int x)
  114. {
  115. int now = root;
  116. while()
  117. {
  118. if(sons[now][] && x <= sub_size[sons[now][]])
  119. now = sons[now][];
  120. else
  121. {
  122. int temp = (sons[now][] ? sub_size[sons[now][]] : ) + cnt[now];
  123. if(x <= temp)
  124. return value[now];
  125. x -= temp;
  126. now = sons[now][];
  127. }
  128. }
  129. }
  130. inline int find_num(int x)
  131. {
  132. int now = root;
  133. while()
  134. {
  135. if(sons[now][] && x <= sub_size[sons[now][]])
  136. now = sons[now][];
  137. else
  138. {
  139. int temp = (sons[now][] ? sub_size[sons[now][]] : ) + cnt[now];
  140. if(x <= temp)
  141. return value[now];
  142. x -= temp;
  143. now = sons[now][];
  144. }
  145. }
  146. }
  147. inline int find_rank(int x)
  148. {
  149. int now = root;
  150. int ans = ;
  151. while()
  152. {
  153. if(x < value[now])
  154. now = sons[now][];
  155. else
  156. {
  157. ans += (sons[now][] ? sub_size[sons[now][]] : );
  158. if(x >= value[now])
  159. {
  160. splay(now);
  161. return ans + ;
  162. }
  163. ans += cnt[now];
  164. now = sons[now][];
  165. }
  166. }
  167. }
  168. inline int find_pre()
  169. {
  170. int now = sons[root][];
  171. while(sons[now][])
  172. now = sons[now][];
  173. return now;
  174. }
  175. inline int find_suffix()
  176. {
  177. int now = sons[root][];
  178. while(sons[now][])
  179. now = sons[now][];
  180. return now;
  181. }
  182. inline void my_delete(int x)
  183. {
  184. int kkk = find_rank(x);
  185. if(cnt[root] > )
  186. {
  187. cnt[root]--;
  188. update(root);
  189. return ;
  190. }
  191. if(!sons[root][] && !sons[root][])
  192. {
  193. S_clear(root);
  194. root = ;
  195. return ;
  196. }
  197. if(!sons[root][])
  198. {
  199. int old_root = root;
  200. root = sons[root][];
  201. f[root] = ;
  202. S_clear(old_root);
  203. return ;
  204. }
  205. else
  206. if(!sons[root][])
  207. {
  208. int old_root = root;
  209. root = sons[root][];
  210. f[root] = ;
  211. S_clear(old_root);
  212. return ;
  213. }
  214. int left_max = find_pre();
  215. int old_root = root;
  216. splay(left_max);
  217. sons[root][] = sons[old_root][];
  218. f[sons[old_root][]] = root;
  219. S_clear(old_root);
  220. update(root);
  221. }
  222. int main()
  223. {
  224. scanf("%d",&m);
  225. for(int i=;i<=m;i++)
  226. {
  227. num = read();
  228. be_dealt = read();
  229. switch(num)
  230. {
  231. case : insert(be_dealt);break;
  232. case : my_delete(be_dealt);break;
  233. case : printf("%d\n",find_rank(be_dealt));break;
  234. case : printf("%d\n",find_num(be_dealt));break;
  235. case : insert(be_dealt);printf("%d\n",value[find_pre()]);my_delete(be_dealt);break;
  236. case : insert(be_dealt);printf("%d\n",value[find_suffix()]);my_delete(be_dealt);break;
  237. }
  238. }
  239. return ;
  240. }

Splay的初步学习的更多相关文章

  1. json2.js的初步学习与了解

    json2.js的初步学习与了解,想要学习json的朋友可以参考下. json2.js的初步学习与了解 1.)该js的下载地址是:http://www.json.org/json2.js 2.)在页面 ...

  2. 老周的ABP框架系列教程 -》 一、框架理论初步学习

    老周的ABP框架系列教程 -- 一.框架理论初步学习   1. ABP框架的来源与作用简介 1.1  简介 1.1.1       ABP框架全称为"ASP.NET Boilerplate ...

  3. 初步学习nodejs,业余用node写个一个自动创建目录和文件的小脚本,希望对需要的人有所帮助

    初步学习nodejs,业余用node写个一个自动创建目录和文件的小脚本,希望对需要的人有所帮助,如果有bug或者更好的优化方案,也请批评与指正,谢谢,代码如下: var fs = require('f ...

  4. EF Codefirst 初步学习(二)—— 程序管理命令 更新数据库

    前提:搭建成功codefirst相关代码,参见EF Codefirst  初步学习(一)--设置codefirst开发模式 具体需要注意点如下: 1.确保实体类库程序生成成功 2.确保实体表类库不缺少 ...

  5. 初步学习python

    自计算机诞生以来,也伴随着计算机语言的诞生,现在,全世界的编程语言有600多种,但流行的编程语言也就20多种. Java和C一直占据着前两名.但是近年来伴随着人工智能的发展,Python发展迅猛,以其 ...

  6. Git的初步学习

    前言 感谢! 承蒙关照~ Git的初步学习 为什么要用Git和Github呢?它们的出现是为了用于提交项目和存储项目的,是一种很方便的项目管理软件和网址地址. 接下来看看,一家公司的基本流程图: 集中 ...

  7. 语法分析器初步学习——LISP语法分析

    语法分析器初步学习——LISP语法分析 本文参考自vczh的<如何手写语法分析器>. LISP的表达式是按照前缀的形式写的,比如(1+2)*(3+4)在LISP中会写成(*(+ 1 2)( ...

  8. 状态保持以及AJAX的初步学习

    嘿嘿,今天学习的有点迷茫哦,主要学习把验证码使用在登录页面时间的一些逻辑,学习这个时间并没有那么的迷惑哦,可是自己写程序时间倒是有点反应迟钝,不过还好总是在最后搞清楚啦,另外就是一步一步的学习是接近项 ...

  9. LinQ的初步学习与总结

    嘿嘿,说起来ORM和LinQ,就感觉离我好遥远的,在学校是没有学习的,所以总感觉学习了LinQ就是大神,现在嘛,终于也体会一点,感觉LinQ只是初步学习,没有太难,当然以后使用在项目中就没有这样的简单 ...

随机推荐

  1. Linux基础实操一

    开启Linux操作系统,要求以root用户登录GNOME图形界面,语言支持选择为汉语 使用快捷键切换到虚拟终端2,使用普通用户身份登录,查看系统提示符 使用命令退出虚拟终端2上登录的用户 使用快捷键切 ...

  2. C# Parallel并发执行相关问题

    1.Parallel并发执行 using System;using System.Collections.Generic;using System.Linq;using System.Text;usi ...

  3. poj2836 状态压缩dp

    自己的做法是枚举i,j作为顶点的矩形,然后再更新状态S,但是这种做法是错误的 正解是先把所有矩形对求出来,然后枚举状态S,每个处理每个状态时再枚举已经求出的矩形对,用旧状态更新新状态 #include ...

  4. 右键菜单添加打开CMD选项

    转载: https://www.cnblogs.com/mkdd/p/8649139.html#undefined 目前用的win7sp1系统,平时打开CMD窗口通常用三种方法:1.win+R然后输入 ...

  5. 为什么访问json接口出现文件下载

    在IE9,10,11下,当服务器端返回数据格式为json,且明确设置Content-Type为”application/json;charset=utf-8“时,会提示文件下载.如图所示: 解决办法是 ...

  6. Java+selenium之WebDriver的抛出异常分析(七)

    NoSuchElementException 1.检查元素的定位器是否正确 2.如果定位器正确,增加休眠时间 3.等待了足够的时间依然找不到的话,更换定位器的定位方式 NoSuchWindowExce ...

  7. Flask-WTF中的csrf保护

    CSRF 保护 这部分文档介绍了 CSRF 保护. 为什么需要 CSRF? Flask-WTF 表单保护你免受 CSRF 威胁,你不需要有任何担心.尽管如此,如果你有不包含表单的视图,那么它们仍需要保 ...

  8. NodeJs——router报错原因

    rout.js var http = require('http'); var url = require('url'); var router = require('./models/router. ...

  9. js中匿名函数和回调函数

    匿名函数: 通过这种方式定义的函数:(没有名字的函数) 作用:当它不被赋值给变量单独使用的时候 1.将匿名函数作为参数传递给其他函数 2.定义某个匿名函数来执行某些一次性任务 var f = func ...

  10. 个人笔记本安装多个jdk(jdk1.7,jdk1.8,jdk1.9,jdk10.0)出现的问题

    1.个人笔记本已经安装jdk1.7,jdk1.8,(之前没有在意这个问题).最近想学习jdk10.0,安装以后,环境变量变成了jdk10.0,就是cmd输入命令java -version,显示版本是j ...