具体是啥,qwq

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

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
#define MAXN 10086666
using namespace std;
int f[MAXN],cnt[MAXN],value[MAXN];
int sons[MAXN][],sub_size[MAXN];
int root,whole_size;
int m,num,be_dealt;
inline int read()
{
int x = ;
int f = ;
char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-')
f = -;
ch = getchar();
}
while(isdigit(ch))
{
x = x * + ch - ;
ch = getchar();
}
return x * f;
}
inline void S_clear(int x)
{
sons[x][] = sons[x][] = ;
f[x] = cnt[x] = value[x] = ;
sub_size[x] = ;
}
inline bool get_which(int x)
{
return sons[f[x]][] == x;
}
inline void update(int x)
{
if(x)
{
sub_size[x] = cnt[x];
if(sons[x][])
sub_size[x] += sub_size[sons[x][]];
if(sons[x][])
sub_size[x] += sub_size[sons[x][]];
}
return ;
}
inline void rotate(int x)
{
int father = f[x];
int g_father = f[father];
int which_son = get_which(x);
sons[father][which_son] = sons[x][which_son ^ ];
f[sons[father][which_son]] = father;
sons[x][which_son ^ ] = father;
f[father] = x;
f[x] = g_father;
if(g_father)
sons[g_father][sons[g_father][] == father] = x;
update(father);
update(x);
}
inline void splay(int x)
{
for(int fa;fa = f[x];rotate(x))
if(f[fa])
rotate((get_which(x)) == get_which(fa) ? fa : x);
root = x;
}
inline void insert(int x)
{
if(!root)
{
whole_size++;
sons[whole_size][] = sons[whole_size][] = f[whole_size] = ;
root = whole_size;
sub_size[whole_size] = cnt[whole_size]++;
value[whole_size] = x;
return ;
}
int now = root;
int fa = ;
while()
{
if(x == value[now])
{
cnt[now]++;
update(now);
update(fa);
splay(now);
break;
}
fa = now;
now = sons[now][value[now] < x];
if(!now)
{
whole_size++;
sons[whole_size][] = sons[whole_size][] = ;
f[whole_size] = fa;
sub_size[whole_size] = cnt[whole_size] = ;
sons[fa][value[fa] < x] = whole_size;
value[whole_size] = x;
update(fa);
splay(whole_size);
break;
}
}
}
inline int find_sum(int x)
{
int now = root;
while()
{
if(sons[now][] && x <= sub_size[sons[now][]])
now = sons[now][];
else
{
int temp = (sons[now][] ? sub_size[sons[now][]] : ) + cnt[now];
if(x <= temp)
return value[now];
x -= temp;
now = sons[now][];
}
}
}
inline int find_num(int x)
{
int now = root;
while()
{
if(sons[now][] && x <= sub_size[sons[now][]])
now = sons[now][];
else
{
int temp = (sons[now][] ? sub_size[sons[now][]] : ) + cnt[now];
if(x <= temp)
return value[now];
x -= temp;
now = sons[now][];
}
}
}
inline int find_rank(int x)
{
int now = root;
int ans = ;
while()
{
if(x < value[now])
now = sons[now][];
else
{
ans += (sons[now][] ? sub_size[sons[now][]] : );
if(x >= value[now])
{
splay(now);
return ans + ;
}
ans += cnt[now];
now = sons[now][];
}
}
}
inline int find_pre()
{
int now = sons[root][];
while(sons[now][])
now = sons[now][];
return now;
}
inline int find_suffix()
{
int now = sons[root][];
while(sons[now][])
now = sons[now][];
return now;
}
inline void my_delete(int x)
{
int kkk = find_rank(x);
if(cnt[root] > )
{
cnt[root]--;
update(root);
return ;
}
if(!sons[root][] && !sons[root][])
{
S_clear(root);
root = ;
return ;
}
if(!sons[root][])
{
int old_root = root;
root = sons[root][];
f[root] = ;
S_clear(old_root);
return ;
}
else
if(!sons[root][])
{
int old_root = root;
root = sons[root][];
f[root] = ;
S_clear(old_root);
return ;
}
int left_max = find_pre();
int old_root = root;
splay(left_max);
sons[root][] = sons[old_root][];
f[sons[old_root][]] = root;
S_clear(old_root);
update(root);
}
int main()
{
scanf("%d",&m);
for(int i=;i<=m;i++)
{
num = read();
be_dealt = read();
switch(num)
{
case : insert(be_dealt);break;
case : my_delete(be_dealt);break;
case : printf("%d\n",find_rank(be_dealt));break;
case : printf("%d\n",find_num(be_dealt));break;
case : insert(be_dealt);printf("%d\n",value[find_pre()]);my_delete(be_dealt);break;
case : insert(be_dealt);printf("%d\n",value[find_suffix()]);my_delete(be_dealt);break;
}
}
return ;
}

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. automaticallyAdjustsScrollViewInsets 详解

    automaticallyAdjustsScrollViewInsets 自动缩进 20 像素 默认是 True 项目中如果有UIViewController 和ScrollView 一般都要设置成f ...

  2. LoadRunner监控window系统各项指标详解

    一.监控系统时,需要监控的项 System 系统 Processor 处理器 Memory 内存 PhysicalDisk 磁盘 Server 服务器 二.指标详解 (一). PhysicalDisk ...

  3. NHibernate入门

    这里是官方的Demo,可以看看,因为我也是通过官方的demo学习的.   https://github.com/nhibernate/nhibernate-core/tree/master/src/N ...

  4. Windows 系统共享文件扫描

    近年来历次泄露的安全事故(工控安全),其主要原因就是内部网络自身的脆弱性问题.对于内部网络的安全检查是很必要的.传统上使用CMD命令  net view 就可以扫描在线的主机但是,主机设置取消QOS的 ...

  5. 集腋成裘-05-angularJS -初识angular

    私以为angular的最大特点是:只关注数据 1.1 angular之:双向绑定 <!DOCTYPE html> <html ng-app=""> < ...

  6. Python os.walk() 方法遍历文件目录

    概述 os.walk() 方法用于通过在目录树中游走输出在目录中的文件名,向上或者向下. os.walk() 方法是一个简单易用的文件.目录遍历器,可以帮助我们高效的处理文件.目录方面的事情. 在Un ...

  7. js中的原型

    一:原型属性 函数本身也是一个包含了方法和属性的对象. 定义一个函数foo(),访问其他对象一样访问该函数的属性: function foo(a, b) { return a * b; } foo.l ...

  8. 使用Docker方式运行Mysql(MariaDB)

    两者差不多.我使用的是MariaDB. 下面的docker命令,挂了数据,配置,映射了端口,指定了root密码,服务端编码. 蛮快的! docker run \ --name mariadb \ -v ...

  9. Pytorch学习笔记

    非线性回归问题的参数求解,反向求导基本流程.Variable 计算时, 它在后台一步步默默地搭建着一个庞大的系统, 叫做计算图, computational graph. 这个图将所有的计算步骤 (节 ...

  10. html知识杂记

    1.HTML中不支持 空格.回车.制表符,它们都会被解析成一个空白字符.2.HTML 是用来描述网页的一种语言.3.元素的内容是开始标签与结束标签之间的内容.4.即使 <br> 在所有浏览 ...