就是非旋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. Spark Streaming性能优化系列-怎样获得和持续使用足够的集群计算资源?

    一:数据峰值的巨大影响 1. 数据确实不稳定,比如晚上的时候訪问流量特别大 2. 在处理的时候比如GC的时候耽误时间会产生delay延迟 二:Backpressure:数据的反压机制 基本思想:依据上 ...

  2. ViewPagerIndicator

    https://github.com/eltld/ViewPagerIndicator

  3. 项目Beta冲刺(团队1/7)

    项目Beta冲刺(团队1/7) 团队名称: 云打印 作业要求: 项目Beta冲刺(团队) 作业目标: 完成项目Beta版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 陈宇 ...

  4. Hero In Maze

    Hero In Maze 时间限制(普通/Java):1000MS/10000MS          执行内存限制:65536KByte 描写叙述 500年前,Jesse是我国最卓越的剑客. 他英俊潇 ...

  5. Android手机摇一摇的实现SensorEventListener

    Android手机摇一摇的实现SensorEventListener 看实例 package com.example.shakeactivity; import android.content.Con ...

  6. SenTestingKit.framework的报错!

    本文转载至http://www.cocoachina.com/ask/questions/show/106912 ld: building for iOS Simulator, but linking ...

  7. debian var目录

    1 /usr和/var /usr,只读数据. /var,可变数据. 2 /var/lib和/var/cache /var/lib,保存应用或者系统可变的状态信息,真的只是状态信息,比如/var/lib ...

  8. es 300G 数据删除 执行计划 curl REST 操作

    es 300G 数据删除 [es union_2017执行计划] [测试执行环境]线上D服务器[测试用例]get:curl -XGET ES:9200/_cat/indices?v post:curl ...

  9. 在C语言中使用libiconv进行编码转换的示例

    libiconv_sample.c #include <stdio.h> #include <malloc.h> #include "libiconv/iconv.h ...

  10. OpenMAX IL介绍与其体系

    1  OpenMAX IL介绍与其体系 这一部分的文档描写叙述 OpenMAX IL的特性与体系. 1.1  OpenMAX IL 简述 OpenMAX IL 软件接口层定义了一套API.用于訪问系统 ...