BZOJ 3224: Tyvj 1728 普通平衡树 pb_ds
来源:互联网 发布:midi伴奏制作软件 编辑:程序博客网 时间:2024/06/10 21:27
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3224
注意老版本 null_mapped_type 新版本null_type
code:
/*1. 插入x数2. 删除x数(若有多个相同的数,因只删除一个)3. 查询x数的排名(若有多个相同的数,因输出最小的排名)4. 查询排名为x的数5. 求x的前驱(前驱定义为小于x,且最大的数)6. 求x的后继(后继定义为大于x,且最小的数)*/#include<ext/pb_ds/assoc_container.hpp>#include<bits/stdc++.h>#include<tr1/unordered_map>using namespace std;using namespace std::tr1;using namespace __gnu_pbds;typedef long long LL;tree<LL, null_mapped_type, less<LL>, rb_tree_tag, tree_order_statistics_node_update>::iterator iter;const int offset = 1e8;int main(){ tree<LL, null_mapped_type, less<LL>, rb_tree_tag, tree_order_statistics_node_update> t; unordered_map<int, int> mp; int n; scanf("%d", &n); while(n--){ int op, x; scanf("%d %d", &op, &x); if(op == 1){ x += offset; t.insert((LL)x << 32 | (mp[x]++)); } else if(op == 2){ x += offset; t.erase((LL)x << 32 | (--mp[x])); } else if(op == 3){ x += offset; printf("%d\n", (int)t.order_of_key((LL)x << 32) + 1); } else if(op == 4){ int ret = *t.find_by_order(x - 1) >> 32; ret -= offset; printf("%d\n", ret); } else if(op == 5){ x += offset; iter = t.lower_bound((LL)x << 32); iter--; int ret = *iter >> 32; ret -= offset; printf("%d\n", ret); } else{ x += offset + 1; iter = t.lower_bound((LL)x << 32); int ret = *iter >> 32; ret -= offset; printf("%d\n", ret); } } return 0;}
阅读全文
0 0
- BZOJ 3224: Tyvj 1728 普通平衡树 pb_ds
- BZOJ 3224: Tyvj 1728 普通平衡树
- BZOJ 3224 Tyvj 1728 普通平衡树
- bzoj 3224: Tyvj 1728 普通平衡树
- 【BZOJ 3224】 Tyvj 1728 普通平衡树
- bzoj 3224/Tyvj 1728 普通平衡树
- bzoj 3224,tyvj 1728普通平衡树
- bzoj 3224: Tyvj 1728 普通平衡树
- BZOJ 3224 Tyvj 1728 普通平衡树
- BZOJ 3224 TYVJ 1728 普通平衡树
- BZOJ 3224:Tyvj 1728 普通平衡树
- 【bzoj 3224】【Tyvj 1728】 普通平衡树
- BZOJ 3224: Tyvj 1728 普通平衡树
- [BZOJ]3224: Tyvj 1728 普通平衡树
- BZOJ 3224: Tyvj 1728 普通平衡树
- 【bzoj 3224】Tyvj 1728 普通平衡树
- BZOJ 3224: Tyvj 1728 普通平衡树
- bzoj 3224: Tyvj 1728 普通平衡树
- OpenCV学习笔记17-直方图
- zImage转换为uImage
- 支持向量机通俗导论(理解SVM的三层境界)
- Android布局文件小结
- BASE64Encoder及BASE64Decoder的正确用法
- BZOJ 3224: Tyvj 1728 普通平衡树 pb_ds
- hdu6103
- 最全的jquery datatables api 使用详解
- 矩阵A+B
- 小X的佛光
- dubbox 发布rest服务调用过程记录
- Spring事务机制详解
- 关于app目前第三方托管平台整理
- SpringCloud教程 | 第三篇: 服务消费者(Feign)