bzoj 3224: Tyvj 1728 普通平衡树【非旋treap】
就是非旋treap的板子
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int N=500005,mod=73939133,bs=997687623;
int q,tot,rt,st=123;
struct qwe
{
int c[2],f,v,s,w;
}t[N];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int rand()
{
return st=1ll*st*bs%mod;
}
void ud(int x)
{
t[x].s=t[t[x].c[0]].s+t[t[x].c[1]].s+1;
}
int hb(int x,int y)
{
if(!x||!y)
return x+y;
if(t[x].w<t[y].w)
{
t[x].c[1]=hb(t[x].c[1],y);
ud(x);
return x;
}
else
{
t[y].c[0]=hb(x,t[y].c[0]);
ud(y);
return y;
}
}
void split(int x,int v,int &l,int &r)
{
if(!x)
{
l=r=0;
return;
}
if(t[x].v<=v)
l=x,split(t[x].c[1],v,t[x].c[1],r);
else
r=x,split(t[x].c[0],v,l,t[x].c[0]);
ud(x);
}
int kth(int x,int k)
{
while(1)
{
if(k<=t[t[x].c[0]].s)
x=t[x].c[0];
else if(k==t[t[x].c[0]].s+1)
return x;
else
k-=t[t[x].c[0]].s+1,x=t[x].c[1];
}
}
void charu(int x)
{
int a,b;
split(rt,x,a,b);
t[++tot].s=1,t[tot].v=x,t[tot].w=rand();
rt=hb(hb(a,tot),b);
}
void shanchu(int x)
{
int a,b,c;
split(rt,x,a,c);
split(a,x-1,a,b);
rt=hb(hb(a,hb(t[b].c[0],t[b].c[1])),c);
}
void rank(int x)
{
int a,b;
split(rt,x-1,a,b);
printf("%d\n",t[a].s+1);
rt=hb(a,b);
}
void real(int x)
{
printf("%d\n",t[kth(rt,x)].v);
}
void pre(int x)
{
int a,b;
split(rt,x-1,a,b);
printf("%d\n",t[kth(a,t[a].s)].v);
rt=hb(a,b);
}
void nxt(int x)
{
int a,b;
split(rt,x,a,b);
printf("%d\n",t[kth(b,1)].v);
rt=hb(a,b);
}
int main()
{
q=read();
while(q--)
{
int o=read();
if(o==1)
charu(read());
else if(o==2)
shanchu(read());
else if(o==3)
rank(read());
else if(o==4)
real(read());
else if(o==5)
pre(read());
else
nxt(read());
}
return 0;
}
bzoj 3224: Tyvj 1728 普通平衡树【非旋treap】的更多相关文章
- BZOJ 3224: Tyvj 1728 普通平衡树 or 洛谷 P3369 【模板】普通平衡树-Splay树模板题
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 22483 Solved: 10130[Submit][S ...
- BZOJ 3224: Tyvj 1728 普通平衡树
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 9629 Solved: 4091[Submit][Sta ...
- BZOJ 3224 TYVJ 1728 普通平衡树 [Treap树模板]
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 7390 Solved: 3122 [Submit][S ...
- BZOJ 3224: Tyvj 1728 普通平衡树 treap
3224: Tyvj 1728 普通平衡树 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除 ...
- BZOJ 3224: Tyvj 1728 普通平衡树 vector
3224: Tyvj 1728 普通平衡树 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除 ...
- BZOJ 3224: Tyvj 1728 普通平衡树(BST)
treap,算是模板题了...我中间还一次交错题... -------------------------------------------------------------------- #in ...
- BZOJ 3224 Tyvj 1728 普通平衡树模板
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 题目大意: 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以 ...
- bzoj 3224: Tyvj 1728 普通平衡树 && loj 104 普通平衡树 (splay树)
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 思路: splay树模板题: 推荐博客:https://blog.csdn.ne ...
- bzoj 3224/Tyvj 1728 普通平衡树(splay)
Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除一个)3. 查询x数的排名(若有多个相同的数 ...
随机推荐
- java的gradle项目的基本配置
plugins { id 'org.springframework.boot' version '2.1.4.RELEASE' id 'java' } apply plugin: 'io.spring ...
- kafka 和 zookeeper 常用命令记录
启动zookeeper zkServer.sh start 启动kafka服务器 kafka-server-start.sh /software/kafka_2.10-0.10.2.1/config/ ...
- 20170218-取值Domain
1.通过视图DD07V, 例子:取SD 凭证类别的DOMAIN(VBTYP)DATA: LT_DD07V TYPE TABLE OF DD07V.SELECT * INTO T_DD07V FROM ...
- C# delegate Action<T> lambda表达式
转载以记录:http://blog.csdn.net/educast/article/details/7219854 在使用 Action<T> 委托时,不必显式定义一个封装只有一个参数的 ...
- ie下文件上传无权访问的问题
最近项目遇到个问题,ie下文件上传无权访问,在网上找了很久才找到答案,原来是因为ie下不能用js触发input=file的点击事件,必须手动点击才可以.
- iOS中UIPickerView常见属性和方法的总结
UIPickerView是iOS中的原生选择器控件,使用方便,用法简单,效果漂亮. @property(nonatomic,assign) id<UIPickerViewDataSource&g ...
- centos 网络连接查看
安装iftop. 这个得先安装epel #yum install epel-replease -y #yum install iftop -y #iftop
- 用Delphi7 调用.NET 2.0的WebService 所要注意的问题(Document格式和UTF8编码)
Delphi7 调用VS.NET 2005开发的基于.NET 2.0的WebService时发生了错误.查阅资料 http://www.community.borland.com/article/bo ...
- ElementUI的Upload上传,配合七牛云储存图片
七牛云服务器的储存区域 存储区域 地域简称 上传域名 华东 z0 服务器端上传:http(s)://up.qiniup.com 华东 z0 客户端上传: http(s)://upload.qiniup ...
- HDU1693 Eat the Trees —— 插头DP
题目链接:https://vjudge.net/problem/HDU-1693 Eat the Trees Time Limit: 4000/2000 MS (Java/Others) Mem ...