学习了下treap

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int inf=<<;
int n,mn,root,delta,tot,ans;
int size[],child[][],cnt[],key[],p[];
void update(int x)
{
size[x]=size[child[x][]]+size[child[x][]]+cnt[x];
}
void rotate(int&x,int t)
{
int y=child[x][t];
child[x][t]=child[y][-t];
child[y][-t]=x;
update(x);
update(y);
x=y;
}
void insert(int&x,int k)
{
if(x)
{
if(key[x]==k) cnt[x]++;
else
{
int t=key[x]<k;
insert(child[x][t],k);
if(p[x]<p[child[x][t]]) rotate(x,t);
}
}
else
{
++tot;
x=tot;
p[x]=rand();
// printf("%d\n",p[x]);
key[x]=k;
cnt[x]=;
}
update(x);
}
void erase(int&x,int k)
{
if(key[x]==k)
{
if(cnt[x]>)
{
cnt[x]--;
update(x);
return;
}
if(!child[x][]&&!child[x][])
{
x=;
return;
}
int t=p[child[x][]]>p[child[x][]];
rotate(x,t);
erase(child[x][t^],k);
} else erase(child[x][key[x]<k],k);
update(x);
}
int find(int x,int k)
{
if(k<=size[child[x][]])
return find(child[x][],k);
k-=size[child[x][]]+cnt[x];
if(k<=) return key[x];
return find(child[x][],k);
}
int findrank(int x,int k)
{
if(key[x]==k) return size[child[x][]]+;
if(key[x]<k) return findrank(child[x][],k)+cnt[x]+size[child[x][]];
if(key[x]>k) return findrank(child[x][],k);
}
void findpro(int x,int k)
{
if(x==) return;
if(key[x]<k)
{
ans=key[x];
findpro(child[x][],k);
} else findpro(child[x][],k);
}
void findnxt(int x,int k)
{
if(x==) return;
if(key[x]>k)
{
ans=key[x];
findnxt(child[x][],k);
} else findnxt(child[x][],k);
}
int main()
{
p[]=-inf;
scanf("%d",&n);
while(n--)
{
int opt,a; scanf("%d%d",&opt,&a);
// printf("----------\nopt=%d\n",opt);
if(opt==) insert(root,a);
if(opt==) erase(root,a);
if(opt==) printf("%d\n",findrank(root,a));
if(opt==) printf("%d\n",find(root,a));
if(opt==) {findpro(root,a);printf("%d\n",ans);ans=;}
if(opt==) {findnxt(root,a);printf("%d\n",ans);ans=;}
// printf("----------\n");
}
return ;
}

bzoj3224的更多相关文章

  1. [BZOJ3224]Tyvj 1728 普通平衡树

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

  2. 【权值线段树】bzoj3224 Tyvj 1728 普通平衡树

    一个板子. #include<cstdio> #include<algorithm> using namespace std; #define N 100001 struct ...

  3. BZOJ3224 洛谷3369 Tyvj 1728 普通平衡树 splay

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ3224 题意概括 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. ...

  4. 【bzoj3224】 Tyvj1728—普通平衡树

    http://www.lydsy.com/JudgeOnline/problem.php?id=3224 (题目链接) 题意 1. 插入x数:2. 删除x数(若有多个相同的数,因只删除一个):3. 查 ...

  5. 【替罪羊树】bzoj3224&luogu3369&cogs1829 [Tyvj 1728]普通平衡树

    [替罪羊树]bzoj3224&luogu3369&cogs1829 [Tyvj 1728]普通平衡树 bzoj 洛谷 cogs 先长点芝士 替罪羊树也是一种很好写的平衡树qwq..替罪 ...

  6. BZOJ3224 Tyvj 1728 普通平衡树(Treap)

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  7. [BZOJ3224]普通平衡树(旋转treap,STL-vector)

    3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 20328  Solved: 8979[Submit][St ...

  8. 【BZOJ3224】普通平衡树(splay)

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

  9. bzoj3224: Tyvj 1728 普通平衡树(平衡树)

    bzoj3224: Tyvj 1728 普通平衡树(平衡树) 总结 a. cout<<(x=3)<<endl;这句话输出的值是3,那么对应的,在splay操作中,当父亲不为0的 ...

  10. [bzoj3224][tyvj1728][普通平衡树] (pb_ds库自带红黑树)

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

随机推荐

  1. 转:大气炫酷焦点轮播图js特效

    使用方法 Step 1. 在html的标签内引入相关文件 <script type="text/javascript" src="js/myfocus-2.0.0. ...

  2. [No000037]操作系统Operating Systems操作系统历史与硬件概况History of OS & Summaries!

    培根:读史使人明智 操作系统的简史 (1955-1965) 计算机非常昂贵,上古神机IBM7094 ,造价在250万美元以上 计算机使用原则:只专注于计算 批处理操作系统(Batch system) ...

  3. NSArray遍历和修改崩溃

    //一.代码 NSArray *array = [self.dataList mutableCopy]; 或 NSArray *array = [NSArray arrayWithArray:self ...

  4. sql将同一个表中的两列Int数据相加,有些数据是空的

    不能这样加! 有些数据为null吧,null+任何值=null 如这句话就不行 update HY_MYGGCYSWCQKB set HY_MYGGCYSWCQKB.Sj_By_Sr=HY_MYGGC ...

  5. 在VisualStudio2013,2015中如何安装自定义项目模板

    For example, I want to install EP prj template: AxWebProject.zip Copy AxWebProject.zip zip file into ...

  6. python读取配置文件

    从/mnt目录下读取section配置文件sample.ini [db] host=192.168.1.116 hostaddr=192.168.1.116 port=5432 dbname=clas ...

  7. PAT 1021. 个位数统计 (15)

    给定一个k位整数N = dk-1*10k-1 + ... + d1*101 + d0 (0<=di<=9, i=0,...,k-1, dk-1>0),请编写程序统计每种不同的个位数字 ...

  8. PAT 1008. 数组元素循环右移问题 (20)

    一个数组A中存有N(N>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A0 A1--AN-1)变换为(AN-M -- AN-1 A0 ...

  9. DLL放在指定目录 以及设置dll调用路径

    一.DLL放在指定目录 在编写C# winform程序中,不免一个项目会有多个工程文件,而这些工程文件之间是相互引用的,所以不想将工程的生成结果(exe或者dll)放在当前工程bin目录下的Debug ...

  10. [转]RabbitMQ消息队列在PHP下的应用

    FROM : http://www.cnblogs.com/phpinfo/p/4104551.html 参考资料: http://www.yuansir-web.com/tag/rabbitmq/ ...