部分还没调到满意的程度,效率比splay略好

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6+11;
unsigned int SEED = 17;
inline int Rand(){
SEED=SEED*1103515245+12345;
return SEED/65536;
}
struct TP{
int son[maxn][2],val[maxn],fix[maxn],size[maxn];
int tot,root;
#define lc son[o][0]
#define rc son[o][1]
void init(){
root=0;
tot=1;
son[0][0]=son[0][1]=val[0]=fix[0]=size[0]=0;
}
void pu(int o){
size[o]=1+size[lc]+size[rc];
}
int node(int v){
son[tot][0]=son[tot][1]=0;
size[tot]=1;
val[tot]=v;
fix[tot]=Rand();
return tot++;
}
int merge(int a,int b){
if(!a)return b;if(!b)return a;
if(fix[a]<fix[b]){
son[a][1]=merge(son[a][1],b);
pu(a);
return a;
}
else{
son[b][0]=merge(a,son[b][0]);
pu(b);
return b;
}
}
void split(int o,int k,int &a,int &b){
if(!o) a=b=0;
else{
if(val[o]<=k){
a=o;
split(rc,k,rc,b);
}
else{
b=o;
split(lc,k,a,lc);
}
pu(o);
}
}
int kth(int o,int k){
while(1){
if(k<=size[lc]) o=lc;
else if(k==size[lc]+1) return o;
else{k-=size[lc]+1;o=rc;}
}
}
////
void insert(int o,int v){
int a,b;
split(root,v,a,b);// if no root
root=merge(merge(a,node(v)),b);
}
void del(int o,int k){
int a,b,c;
split(root,k,a,c);
split(a,k-1,a,b);
b=merge(son[b][0],son[b][1]);
root=merge(merge(a,b),c);
}
int krank(int k){
int a,b;
split(root,k-1,a,b);
int ans=size[a]+1;
root=merge(a,b);
return ans; }
int rankk(int k){
return val[kth(root,k)];
}
int pre(int k){
int a,b;
split(root,k-1,a,b);
int ans=val[kth(a,size[a])];//
root=merge(a,b);
return ans;
}
int succ(int k){
int a,b;
split(root,k,a,b);
int ans=val[kth(b,1)];
root=merge(a,b);
return ans;
}
}tp;
int main(){
int n,op,x,a,b,c;
while(scanf("%d",&n)^-1){
tp.init();
for(int i = 1; i <= n;i++){
scanf("%d%d",&op,&x);
if(op==1) tp.insert(tp.root,x);
if(op==2) tp.del(tp.root,x);
if(op==3) printf("%d\n",tp.krank(x));
if(op==4) printf("%d\n",tp.rankk(x));
if(op==5) printf("%d\n",tp.pre(x));
if(op==6) printf("%d\n",tp.succ(x));
}
}
return 0;
}

BZOJ 3224 Treap的更多相关文章

  1. Luogu 3369 / BZOJ 3224 - 普通平衡树 - [无旋Treap]

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 https://www.luogu.org/problemnew/show/P3 ...

  2. BZOJ 3224 普通平衡树(Treap模板题)

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

  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 - 普通平衡树 - [Treap][Splay]

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

  5. [bzoj 3224]手写treap

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3224 bzoj不能用time(0),看到这个博客才知道,我也RE了好几发…… #inclu ...

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

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

  7. BZOJ - 3224 Tyvj 1728 普通平衡树 (treap/树状数组)

    题目链接 treap及树状数组模板题. treap版: #include<bits/stdc++.h> using namespace std; typedef long long ll; ...

  8. BZOJ - 3224 可持久化Treap 树形操作

    这个题目去年就做过了,这次稍微改了一下 都是基础操作 #include<iostream> #include<algorithm> #include<cstdio> ...

  9. bzoj 3224: Tyvj 1728 普通平衡树【非旋treap】

    就是非旋treap的板子 #include<iostream> #include<cstdio> #include<cstdlib> using namespace ...

随机推荐

  1. 一个可用模板的Xml描述

    <?xml version="1.0" encoding="utf-8"?> <VMTEMPLATE> <ID>48< ...

  2. c# 获取客户端ip、mac、机器名、操作系统、浏览器信息

    d using System; using System.Collections.Generic; using System.Linq; using System.Web; using System. ...

  3. logback 中文手册

    摘自:http://aub.iteye.com/blog/1896611 logback 中文手册 博客分类:  Log loglogbackloback手册loback中文手册  logback 常 ...

  4. QT开发环境

    代码实现界面和槽 代码实现界面和槽 在上述工程的dialog.h中添加如下加黑代码: 加入头文件: #include <QLabel> #include <QLineEdit> ...

  5. 编写高质量代码改善C#程序的157个建议——建议2: 使用默认转型方法

    建议2: 使用默认转型方法 除了字符串操作外,程序员普遍会遇到的第二个问题是:如何正确地对类型实现转型.在上一个建议中,从int转型为string,我们使用了类型int的ToString方法.在大部分 ...

  6. RobotFramework添加自定义关键字实战

    背景: 此篇文章是上一篇博客python的requests库怎么发送带cookies的请求的后续,上一篇只是使用python脚本调试通过了,接下来要把我们的方法封装为关键字,在RF中调用. 实施: 一 ...

  7. URLRewrite 实现方法详解

    所谓的伪静态页面,就是指的URL重写,在ASP.NET中实现非常简单首先你要在你的项目里引用两个DLL:ActionlessForm.dll.URLRewriter.dll,真正实现重写的是 URLR ...

  8. 阿里云RDS外网无法访问解决办法

    为了安全起见,阿里云的RDS数据库设置只能内网连接,那么为了方便查询数据,我每次都去连接内网服务器远程桌面. 这次我因为网络问题,远程桌面非常不稳定,一会掉线一会掉线,只能另想办法. 同事那里有个批处 ...

  9. C#ADO.NET基础二

    DataAdapter的使用,批量增删改 1.使用DataAdapter查询 private void Select2() { try { using (SQLiteConnection conn = ...

  10. My97DatePicker常用日期格式

    WdatePicker({ minDate: '%y-%M-%d', maxDate: '#F{$dp.$D(\'GradeEndDate\',{d:-1});}' }); WdatePicker({ ...