BZOJ 3224 Treap
部分还没调到满意的程度,效率比splay略好
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+11;
unsigned int SEED = 17;
inline int Rand(){
SEED=SEED*1103515245+12345;
return SEED/65536;
}
struct TP{
int son[maxn][2],val[maxn],fix[maxn],size[maxn];
int tot,root;
#define lc son[o][0]
#define rc son[o][1]
void init(){
root=0;
tot=1;
son[0][0]=son[0][1]=val[0]=fix[0]=size[0]=0;
}
void pu(int o){
size[o]=1+size[lc]+size[rc];
}
int node(int v){
son[tot][0]=son[tot][1]=0;
size[tot]=1;
val[tot]=v;
fix[tot]=Rand();
return tot++;
}
int merge(int a,int b){
if(!a)return b;if(!b)return a;
if(fix[a]<fix[b]){
son[a][1]=merge(son[a][1],b);
pu(a);
return a;
}
else{
son[b][0]=merge(a,son[b][0]);
pu(b);
return b;
}
}
void split(int o,int k,int &a,int &b){
if(!o) a=b=0;
else{
if(val[o]<=k){
a=o;
split(rc,k,rc,b);
}
else{
b=o;
split(lc,k,a,lc);
}
pu(o);
}
}
int kth(int o,int k){
while(1){
if(k<=size[lc]) o=lc;
else if(k==size[lc]+1) return o;
else{k-=size[lc]+1;o=rc;}
}
}
////
void insert(int o,int v){
int a,b;
split(root,v,a,b);// if no root
root=merge(merge(a,node(v)),b);
}
void del(int o,int k){
int a,b,c;
split(root,k,a,c);
split(a,k-1,a,b);
b=merge(son[b][0],son[b][1]);
root=merge(merge(a,b),c);
}
int krank(int k){
int a,b;
split(root,k-1,a,b);
int ans=size[a]+1;
root=merge(a,b);
return ans;
}
int rankk(int k){
return val[kth(root,k)];
}
int pre(int k){
int a,b;
split(root,k-1,a,b);
int ans=val[kth(a,size[a])];//
root=merge(a,b);
return ans;
}
int succ(int k){
int a,b;
split(root,k,a,b);
int ans=val[kth(b,1)];
root=merge(a,b);
return ans;
}
}tp;
int main(){
int n,op,x,a,b,c;
while(scanf("%d",&n)^-1){
tp.init();
for(int i = 1; i <= n;i++){
scanf("%d%d",&op,&x);
if(op==1) tp.insert(tp.root,x);
if(op==2) tp.del(tp.root,x);
if(op==3) printf("%d\n",tp.krank(x));
if(op==4) printf("%d\n",tp.rankk(x));
if(op==5) printf("%d\n",tp.pre(x));
if(op==6) printf("%d\n",tp.succ(x));
}
}
return 0;
}
BZOJ 3224 Treap的更多相关文章
- Luogu 3369 / BZOJ 3224 - 普通平衡树 - [无旋Treap]
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 https://www.luogu.org/problemnew/show/P3 ...
- BZOJ 3224 普通平衡树(Treap模板题)
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 14301 Solved: 6208 [Submit][ ...
- BZOJ 3224 TYVJ 1728 普通平衡树 [Treap树模板]
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 7390 Solved: 3122 [Submit][S ...
- BZOJ 3224 - 普通平衡树 - [Treap][Splay]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3224 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中 ...
- [bzoj 3224]手写treap
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3224 bzoj不能用time(0),看到这个博客才知道,我也RE了好几发…… #inclu ...
- BZOJ 3224: Tyvj 1728 普通平衡树 treap
3224: Tyvj 1728 普通平衡树 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除 ...
- BZOJ - 3224 Tyvj 1728 普通平衡树 (treap/树状数组)
题目链接 treap及树状数组模板题. treap版: #include<bits/stdc++.h> using namespace std; typedef long long ll; ...
- BZOJ - 3224 可持久化Treap 树形操作
这个题目去年就做过了,这次稍微改了一下 都是基础操作 #include<iostream> #include<algorithm> #include<cstdio> ...
- bzoj 3224: Tyvj 1728 普通平衡树【非旋treap】
就是非旋treap的板子 #include<iostream> #include<cstdio> #include<cstdlib> using namespace ...
随机推荐
- Linux 与 BSD
1)Linux 与 BSD 有什么不同? http://linux.cn/article-3186-1.html 2)BSD(Unix)家族 http://blog.csdn.net/cradmin/ ...
- 数字图像处理实验(13):PROJECT 05-04,Parametric Wiener Filter 标签: 图像处理MATLAB 2017-05-27 10:59
实验要求: Objective: To understand the high performance of the parametric Wiener Filter in image restora ...
- Django--form基础
一.Django--form功能 用户提交数据验证 生成html标签 二.基础实例 需求 利用Django的form功能,接收用户注册信息. urls.py 1 2 3 4 5 from app01 ...
- 3、python的传入参数
转载:https://blog.csdn.net/abc_12366/article/details/79627263 1.位置参数: def func(a, b): print(a+b) func( ...
- SVN下载地址及注意事项
SVN下载地址:VisualSVN:http://www.visualsvn.com/server/download 服务器端(添加仓库和用户)TortoiseSVN:http://torto ...
- [转]sessionStorage()和localStorage()的用法
JS的本地保存localStorage.sessionStorage用法总结: 1. localStorage.sessionStorage是Html5的特性,IE7以下浏览器不支持 为什么要掌握lo ...
- CentOS7-扩容挂载磁盘
1.1查看新磁盘,可以看到/dev/sdb是新的未挂载的磁盘: [root@localhost ~]# fdisk -l 1.2硬盘分区 ,进入fdisk模式 进入fdisk模式 [root@loca ...
- angular 守卫路由
import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; im ...
- IDEA的一些常用快捷键以及配置
IDEA常用快捷键: 保存:ctrl + s 关闭当前文件:ctrl + F4 撤销:ctrl + z 反撤销:ctrl + shift + z 查看方法实现类:ctrl + alt + B 移动 ...
- ubuntu14.10,安装ksnapshot(截图软件)
Linux:ubuntu14.10 ubuntu软件中心对它的描述:KSnapshot captures images of the screen. It can capture the whole ...