bzoj 3224 普通平衡树 vactor的妙用
3224: Tyvj 1728 普通平衡树
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://www.lydsy.com/JudgeOnline/problem.php?id=3224
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
Sample Input
1 106465
4 1
1 317721
1 460929
1 644985
1 84185
1 89851
6 81968
1 492737
5 493598
Sample Output
84185
492737
HINT
题意
题解:
用一个vector来做
虽然感觉用set也行
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //无限大
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
//**************************************************************************************
inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
} vector<int> q;
int main()
{
int t=read();
while(t--)
{
int n=read(),m=read();
if(n==)
q.insert(upper_bound(q.begin(),q.end(),m),m);
if(n==)
q.erase(lower_bound(q.begin(),q.end(),m));
if(n==)
printf("%d\n",lower_bound(q.begin(),q.end(),m)-q.begin()+);
if(n==)
printf("%d\n",q[m-]);
if(n==)
printf("%d\n",*--lower_bound(q.begin(),q.end(),m));
if(n==)
printf("%d\n",*upper_bound(q.begin(),q.end(),m));
}
}
bzoj 3224 普通平衡树 vactor的妙用的更多相关文章
- Luogu 3369 / BZOJ 3224 - 普通平衡树 - [无旋Treap]
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 https://www.luogu.org/problemnew/show/P3 ...
- BZOJ 3224 普通平衡树(Treap模板题)
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 14301 Solved: 6208 [Submit][ ...
- Luogu 3369 / BZOJ 3224 - 普通平衡树 - [替罪羊树]
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 https://www.luogu.org/problemnew/show/P3 ...
- BZOJ 3224 - 普通平衡树 - [Treap][Splay]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3224 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中 ...
- BZOJ 3224 普通平衡树
这个是第一份完整的treap代码.嗯...虽然抄的百度的版,但还是不错的. !bzoj上不能用srand. #include<iostream>#include<cstdio> ...
- BZOJ 3224 普通平衡树(树状数组)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=3224 题意:维护以下操作:(1)插入x:(2)删除x(若有多个相同的数,只删除一个)(3 ...
- BZOJ 3224 普通平衡树 | 平衡树模板
#include <cstdio> #include <cmath> #include <cstring> #include <algorithm> # ...
- bzoj 3224 裸平衡树
裸的平衡树,可以熟悉模板用,写题写不出来的时候可以A以下缓解下心情. /************************************************************** P ...
- BZOJ 3224: Tyvj 1728 普通平衡树
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 9629 Solved: 4091[Submit][Sta ...
随机推荐
- struts的标签
<%@ taglib uri="/struts-tags" prefix="s"%> <%@ taglib uri="/WEB-IN ...
- Cesium 初始化Viewer
<pre name="code" class="javascript"><script> var viewer = new Cesium ...
- error: expected expression before ‘struct
Linux C/C++编程时常会遇到“error: expected expression before ‘struct’”错误,此错误一般是由未定义的宏(宏里套宏)或参量引起,导致编译器判断当前语句 ...
- Oracle dblink的说明和简单使用
在跨数据库查询的时候时常会用到dblink,例如:两台不同的数据库服务器,从一台数据库服务器的一个用户读取另一台数据库服务器下面的某个schema的数据,这个时候,使用dblink能够很方便的实现.d ...
- 【转】doxygen+graphviz生成工程中的类继承树及函数调用图
转自----hequn8128 在阅读代码量比较多的项目时,类的继承树和函数调用图能够直观地向我们显示类之间或者函数之间的各种关系,方便我们了解程序的整体框架,很多时候可以起到事半功倍的作用.这里尝试 ...
- 将dubbo框架里的服务提供者迁移进k8s里,以docker提供服务时要注意的细节
在将dubbo框架里的服务提供者迁移进k8s时,有几个注意事项: 1, 要为默认情况下,dubbo会将k8s里的pod ip地址作为注册服务的地址,所以这个地址需要被改写(ip测试过,行得通,而dns ...
- Hadoop(八)Hadoop数据压缩与企业级优化
一 Hadoop数据压缩 1.1 概述 压缩技术能够有效减少底层存储系统(HDFS)读写字节数.压缩提高了网络带宽和磁盘空间的效率.在Hadood下,尤其是数据规模很大和工作负载密集的情况下,使用数据 ...
- 【LOJ】#2131. 「NOI2015」寿司晚宴
题解 怎么NOI2015D1--全是一眼秒的sb题--然后我代码全都写跪一遍= = 要是NOI2015是IOI赛制我就可以AK啦(大雾) 代码能力直线下降,NOI2018滚粗预定了啊TAT 我是不是要 ...
- Oracle 子查询和组函数练习
SELECT * FROM emp; SELECT * FROM dept; 1.查询公司员工工资的最大值,最小值,平均值和总和. SELECT MAX(sal) AS 工资最大值, MIN(sal) ...
- HTML如何创建二级目录
#classify ul li div{width:100px; height:200px; display:none; position:absolute; left:100px; top ...