BZOJ 3224: Tyvj 1728 普通平衡树 vector
2015-12-21 16:40
507 查看
3224: Tyvj 1728 普通平衡树
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.每个数的数据范围:[-1e7,1e7]
Source
题解:vector水过
//meek///#include<bits/stdc++.h> #include <iostream> #include <cstdio> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <map> #include <set> #include <stack> #include <sstream> #include <vector> using namespace std ; #define mem(a) memset(a,0,sizeof(a)) #define pb push_back #define fi first #define se second #define MP make_pair typedef long long ll; const int N = 100005; const int inf = 99999999; const int mod= 1000000007; 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))); } }
代码
相关文章推荐
- 为您的Android,iOS等应用加入声波传输功能
- crontab定时任务不执行
- Struts2值栈和ognl表达式
- css3 中的尺寸单位
- Android学习笔记(23):列表项的容器—AdapterView的子类们
- echarts学习总结(二):一个页面存在多个echarts图形,图形自适应窗口大小
- [note] Iterator and Iterable
- unity3D []
- STM32F4 开发笔记3: 定时器2-5的使用方法
- POJ 3278 Catch That Cow(追赶母牛)
- ARM下的国密SM3软实现遇到的坑
- 多元统计分析及R语言建模-第6章 判别分析
- BeagleBone Black开发环境
- linux系统的时间调整
- TexLive下使用resumecls中/英文简历模板(Ubuntu 12.04)
- CXF学习笔记一(CXF发布与调用WebService)
- Linux实践篇--linux软件的安装,更新与卸载
- QWebView和js交互
- Linux实践篇--linux软件的安装,更新与卸载
- 内存管理