具体是啥,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. 第八单元 正文处理命令及tar命令

    使用cat命令进行文件的纵向合并  两种文件的纵向合并方法  归档文件和归档技术 归档的目的 什么是归档 tar命令的功能 tar命令的常用选项 使用tar命令创建.查看及抽取归档文件 使用tar命令 ...

  2. dubbo源码之服务消费

    消费端启动初始化过程: 消费端的代码解析也是从配置文件解析开始的,服务发布对应的<dubbo:service,解析xml的时候解析了一个ServiceBean,并且调用ServiceConfig ...

  3. 添加按钮 table增加一行 删减按钮 table去掉一行

    需求描述:做的一个AA新增功能,同时可以为这个即将新增的AA添加内容,而且AA的内容默认展示一行列表,点击添加按钮后出现下一行列表 解决思路:页面首先展示一个表头和列表的一行,作为默认展示的一行列表, ...

  4. laravel 频率限制throttle

    在 Laravel 5.6 中,还引入了频率限制功能.所谓频率限制,指的是在指定时间单个用户对某个路由的访问次数限制,该功能有两个使用场景,一个是在某些需要验证/认证的页面限制用户失败尝试次数,提高系 ...

  5. Coding配合git使用时遇到的问题

    转载整理: https://www.jianshu.com/p/b23cd00cffa6 https://www.cnblogs.com/yidoucai/p/5228763.html https:/ ...

  6. Java 获取屏幕的宽、高

    import java.awt.Toolkit; public class GetScreenSize { public static void main(String[] args) { int s ...

  7. python提取文件中的方法名称

    #提取文件中的方法名称 # -*- coding:utf-8 -*- def Query_Method(filepath): file = open(filepath,'r',encoding= 'U ...

  8. Windows文件系统

    微软在Dos/Windows系列操作系统中共使用了6种不同的文件系统(包括即将在windows的下一个版本中使用的Winfs).它们分别是:FAt12.FAT16.FAT32.NTFS.NTFS5.0 ...

  9. VOC数据集生成代码使用说明

    #split.py 文件 输入格式为images ,和标签txt文件,txt中的数据为坐标值共8个. import os import numpy as np import math import c ...

  10. linux:安装并使用mongo

    1.下载mongo:  curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz 2.解压: tar -zxvf ...