就是非旋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】的更多相关文章

  1. BZOJ 3224: Tyvj 1728 普通平衡树 or 洛谷 P3369 【模板】普通平衡树-Splay树模板题

    3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 22483  Solved: 10130[Submit][S ...

  2. BZOJ 3224: Tyvj 1728 普通平衡树

    3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 9629  Solved: 4091[Submit][Sta ...

  3. BZOJ 3224 TYVJ 1728 普通平衡树 [Treap树模板]

    3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 7390  Solved: 3122 [Submit][S ...

  4. BZOJ 3224: Tyvj 1728 普通平衡树 treap

    3224: Tyvj 1728 普通平衡树 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除 ...

  5. BZOJ 3224: Tyvj 1728 普通平衡树 vector

    3224: Tyvj 1728 普通平衡树 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除 ...

  6. BZOJ 3224: Tyvj 1728 普通平衡树(BST)

    treap,算是模板题了...我中间还一次交错题... -------------------------------------------------------------------- #in ...

  7. BZOJ 3224 Tyvj 1728 普通平衡树模板

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 题目大意: 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以 ...

  8. bzoj 3224: Tyvj 1728 普通平衡树 && loj 104 普通平衡树 (splay树)

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 思路: splay树模板题: 推荐博客:https://blog.csdn.ne ...

  9. bzoj 3224/Tyvj 1728 普通平衡树(splay)

    Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除一个)3. 查询x数的排名(若有多个相同的数 ...

随机推荐

  1. 集成CCFlow工作流与GPM的办公系统驰骋CCOA介绍(三)

    通过组织结构能够对项目的岗位.部门.人员进行增删改操作. 加入新部门.并为新部门加入人员: 选中部门后,点击鼠标右键,能够选择加入平级部门或下属部门. 新建部门时,须要给部门设置部门编号.名称.与部门 ...

  2. 关于从 coding 拉项目的操作

    介绍:coding是托管代码的仓库   sourceTree 是把代码提交到coding的界面化工具 1.通过百度 登录coding账号

  3. Spring Boot与Micronaut性能比较

    文章转载出处:微信公众号——锅外的大佬 链接:https://mp.weixin.qq.com/s/MdBByJ0ju-rROKg7jsWygA 今天我们将比较两个在JVM上构建微服务的框架:Spri ...

  4. 李洪强iOS开发之- 点击屏幕遮挡键盘

    李洪强iOS开发之- 点击屏幕遮挡键盘 实现的效果:  01 - 给当前的view添加点击事件,使点击屏幕的时候,让键盘退出 /** * 点击屏幕 隐藏键盘 * * @param tap */-(vo ...

  5. Andriod Atom x86模拟器启动报错。

    用Inter Atom模式的Android模拟器启动报一下错误: Starting emulator for AVD 'new' emulator: ERROR: x86 emulation curr ...

  6. SSM整理笔记2——jar包整理

    github:https://github.com/lakeslove/SSM 需要的jar包 springMVC和spring: spring.RELEASE.jar spring.RELEASE. ...

  7. gitlab merge过程

    基本步骤如下: 以我的分支为例 1.创建本地分支,命令 git checkout -b liuping_develop2.创建好分支后提交到远程 ,命令 git push origin liuping ...

  8. char* strcpy( char* dest, const char* src ), int binary_search(int *arr, int key, int n), 可能的实现

    #include <stdio.h> char* stringCopy( char* dest, const char* src ) { size_t i = 0; while (dest ...

  9. C# partial分部类和分部方法

    1.https://www.cnblogs.com/xcsn/p/7533238.html 它是一个关键字修饰符.可以将类或结构.接口或方法的定义拆分到两个或更多个源文件中. 每个源文件包含类型或方法 ...

  10. 处理TCP连包的一小段代码

    学习网络编程也有一段时间了,一直听说TCP数据会连包,但一直不知道怎么测试好.最近测试了下:发送方使用对列,将发送的数据存入队列,然后开线程,专门发送.发送多包数据之间不延时.在接收方,他们确实连在一 ...