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数的排名(若有多个相同的数 ...
随机推荐
- HTML URL编码规则
将空格转换为加号(+) 对0-9,a-z,A-Z之间的字符保持不变 对于所有其他的字符,用这个字符的当前字符集编码在内存中的十六进制格式表示,并在每个字节前加上一个百分号(%).如字符“+”用%2B表 ...
- CSP:使用CryptoAPI解码X509证书内容
微软的CryptoAPI提供了一套解码X509证书的函数,一个X509证书解码之后,得到一个PCCERT_CONTEXT类型的结构体指针. 通过该结构体,我们就能够获取想要的证书项和属性等. X509 ...
- openwrt 实现hotplug-button
<*> kmod-gpio-button-hotplug................Simple GPIO Button Hotplug driver gpio-button-hotp ...
- [rabbitmq-discuss] Exactly Once Delivery
[rabbitmq-discuss] Exactly Once Delivery http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2010-A ...
- firefox 45 版本
在做项目的时候,发现45版本的firefox浏览器.声明函数要放在调用者的上方.而firefox的47,48版本则没有这种情况发生.
- luogu3373 【模板】线段树2
题目大意: 已知一个数列,你需要进行下面三种操作:1.将某区间每一个数乘上x2.将某区间每一个数加上x3.求出某区间每一个数的和 本线段树的标记是个二元组:add和mul,其代表将一个线段中的每一个点 ...
- Vue : props 使用细节(父组件传递数据给子组件)
props使用细节 在Vue.js中我们可以使用 props 实现父组件传递数据给子组件,下面我们总结一下props的使用细节 1.基础类型检查 2.必填数据 3.默认值 4.自定义验证函数 其中每一 ...
- webpack与grunt/glub 的比较
webpack.grunt.glub 都是前端打包的工具: grunt/gulp 的工作方式是:在一个配置文件中,指明对某些文件进行压缩.组合.检查等任务的具体步骤,然后在运行中输入相应的命令. we ...
- git apply、git am打补丁.diff 和 .patch【转】
本文转载自:https://www.jianshu.com/p/e5d801b936b6 前提: 生成patch: git format-patch -M master 生成指定patch,0163b ...
- Linux:NFS文件共享问题重新认识
之前也搭建过nfs,服务器之间目录里面的文件同享也一直正常.今天有现场反映,搭建nfs后,客户端文件在服务器端看不见. 在我之前的认识里,服务器端搭建好并启动nfs服务,客户端mount后,客户端.服 ...