就是非旋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. android-custom-tab-with-viewpager

    https://github.com/eltld/android-custom-tab-with-viewpager

  2. Django-配置celery

    首先需要安装的包 pip install cellerypip install django-cellery pip install django-cellery-results pip instal ...

  3. JavaScript 的 MVP 框架 Riot.js

    Riot.js 详细介绍 Riot.js是一个客户端模型-视图-呈现(MVP)框架并且它非常轻量级甚至小于1kb.尽管他的大小令人难以置信,所有它能构建的有如下:一个模板引擎,路由,甚至是库和一个严格 ...

  4. OpenCV2.3.1在CentOS6.5下的安装

    安装的linux版本号是centos6.5.选择的是opencv2.3.1.不是非常新的版本号. 由于在安装opencv2.4.9的时候.make的过程中出现了问题. 一:安装依赖包 依赖包用yum安 ...

  5. NIO原理图

  6. JavaScript算法题(一) && 数组reduce使用

    可参考Array.reduce用法 1. 请编写getMissingElement函数,返回给定数组中缺少的元素(数组里的元素为0~9,只会缺失一个). Example: getMissingElem ...

  7. POJ3579 Median —— 二分

    题目链接:http://poj.org/problem?id=3579 Median Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  8. 从零开始徒手撸一个vue的toast弹窗组件

    相信普通的vue组件大家都会写,定义 -> 引入 -> 注册 -> 使用,行云流水,一气呵成,但是如果我们今天是要自定义一个弹窗组件呢? 首先,我们来分析一下弹窗组件的特性(需求): ...

  9. poj 1094 Sorting It All Out 解题报告

    题目链接:http://poj.org/problem?id=1094 题目意思:给出 n 个待排序的字母 和 m 种关系,问需要读到第 几 行可以确定这些字母的排列顺序或者有矛盾的地方,又或者虽然具 ...

  10. 各种java生成word解决方案的优缺点对比

    解决方案 优点 缺点 Jacob 功能强大 直接调用VBA接口,程序异常复杂:服务器必须是:windows系统+安装Office:服务器端自动化com接口容易产生死进程造成服务器宕机 Apache P ...