(vector通过)bzoj3224: Tyvj 1728 普通平衡树
2017-08-18 15:43
423 查看
3224: Tyvj 1728 普通平衡树
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 15204 Solved: 6614
[Submit][Status][Discuss]
Description
您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数
2. 删除x数(若有多个相同的数,因只删除一个)
3. 查询x数的排名(若有多个相同的数,因输出最小的排名)
4. 查询排名为x的数
5. 求x的前驱(前驱定义为小于x,且最大的数)
6. 求x的后继(后继定义为大于x,且最小的数)
Input
第一行为n,表示操作的个数,下面n行每行有两个数opt和x,opt表示操作的序号(1<=opt<=6)Output
对于操作3,4,5,6每行输出一个数,表示对应答案Sample Input
101 106465
4 1
1 317721
1 460929
1 644985
1 84185
1 89851
6 81968
1 492737
5 493598
Sample Output
10646584185
492737
HINT
1.n的数据范围:n<=1000002.每个数的数据范围:[-2e9,2e9]
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
vector<int >s;
int main() {
int n,op,x;
scanf("%d",&n);
while(n--) {
scanf("%d%d",&op,&x);
if(op==1)
s.insert(upper_bound(s.begin(),s.end(),x),x);
if(op==2)
s.erase(lower_bound(s.begin(),s.end(),x));
if(op==3)
printf("%d\n",lower_bound(s.begin(),s.end(),x)-s.begin()+1);
if(op==4)
printf("%d\n",s[x-1]);
if(op==5)
printf("%d\n",*--(lower_bound(s.begin(),s.end(),x)));
if(op==6)
printf("%d\n",*(upper_bound(s.begin(),s.end(),x)));
}
}
相关文章推荐
- BZOJ-3224 普通平衡树 TYVJ-1728 Treap + Vector
- BZOJ 3224: Tyvj 1728 普通平衡树 vector
- BZOJ 3224: Tyvj 1728 普通平衡树
- BZOJ 3224 Tyvj 1728 普通平衡树
- BZOJ 3224: Tyvj 1728 普通平衡树 替罪羊树
- BZOJ 3224: Tyvj 1728 普通平衡树
- BZOJ 3224 Tyvj 1728 普通平衡树——treap
- BZOJ 3224: Tyvj 1728 普通平衡树
- bzoj3224 Tyvj 1728 普通平衡树(splay/treap)
- BZOJ 3224: Tyvj 1728 普通平衡树 [Splay]【数据结构】
- BZOJ3224: Tyvj 1728 普通平衡树
- bzoj 3224: Tyvj 1728 普通平衡树(splay 模板题)
- 【bzoj 3224】【Tyvj 1728】 普通平衡树
- BZOJ 3224 Tyvj 1728 普通平衡树 | Splay 板子+SPlay详细讲解
- 【bzoj3224】Tyvj 1728 普通平衡树
- _bzoj3224 Tyvj 1728 普通平衡树【Splay】
- bzoj3224 Tyvj 1728 普通平衡树(名次树+处理相同)
- 【BZOJ3224】【codevs4543】【tyvj1728】普通平衡树,第一次的splay
- bzoj 3224: Tyvj 1728 普通平衡树
- BZOJ3224[Tyvj 1728 普通平衡树]题解--Treap