BZOJ 3224: Tyvj 1728 普通平衡树 vector
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
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
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 = ;
const int inf = ;
const int mod= ; vector<int >s; int main() {
int n,op,x;
scanf("%d",&n);
while(n--) {
scanf("%d%d",&op,&x);
if(op==)
s.insert(upper_bound(s.begin(),s.end(),x),x);
if(op==)
s.erase(lower_bound(s.begin(),s.end(),x));
if(op==)
printf("%d\n",lower_bound(s.begin(),s.end(),x)-s.begin()+);
if(op==)
printf("%d\n",s[x-]);
if(op==)
printf("%d\n",*--(lower_bound(s.begin(),s.end(),x)));
if(op==)
printf("%d\n",*(upper_bound(s.begin(),s.end(),x)));
}
}
代码
BZOJ 3224: Tyvj 1728 普通平衡树 vector的更多相关文章
- BZOJ 3224: Tyvj 1728 普通平衡树 or 洛谷 P3369 【模板】普通平衡树-Splay树模板题
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 22483 Solved: 10130[Submit][S ...
- BZOJ 3224: Tyvj 1728 普通平衡树
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 9629 Solved: 4091[Submit][Sta ...
- BZOJ 3224 TYVJ 1728 普通平衡树 [Treap树模板]
3224: Tyvj 1728 普通平衡树 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 7390 Solved: 3122 [Submit][S ...
- BZOJ 3224: Tyvj 1728 普通平衡树 treap
3224: Tyvj 1728 普通平衡树 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除 ...
- BZOJ 3224: Tyvj 1728 普通平衡树(BST)
treap,算是模板题了...我中间还一次交错题... -------------------------------------------------------------------- #in ...
- BZOJ 3224 Tyvj 1728 普通平衡树模板
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 题目大意: 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以 ...
- bzoj 3224: Tyvj 1728 普通平衡树 替罪羊树
题目链接 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除一个)3. 查询x数的排名(若有多个相同的数,因输出最小的 ...
- bzoj 3224: Tyvj 1728 普通平衡树 && loj 104 普通平衡树 (splay树)
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3224 思路: splay树模板题: 推荐博客:https://blog.csdn.ne ...
- bzoj 3224/Tyvj 1728 普通平衡树(splay)
Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除一个)3. 查询x数的排名(若有多个相同的数 ...
随机推荐
- hdu 2647 Reward
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2647 Reward Description Dandelion's uncle is a boss o ...
- 37.altium designer中的class和rules?
在布局布线工程中,遇到复杂工程时,难免要进行class和rules的设置,经过试验证明,class和rules的子目录是有优先级的.
- java卡与native卡的区别
JavaCard Native 功能特性 开发语言 l 纯面向对象的Java语言的子集. Java语言先进灵活,开发调试速度快,实现灵活. l Java没有指针,并且有内部安全机制可以有效的避 ...
- Spark系列—02 Spark程序牛刀小试
一.执行第一个Spark程序 1.执行程序 我们执行一下Spark自带的一个例子,利用蒙特·卡罗算法求PI: 启动Spark集群后,可以在集群的任何一台机器上执行一下命令: /home/spark/s ...
- github 使用体会
开始使用git: 在本机上安装git,听一些同学说他们当时用的是github的中文版即oschina开源中国,似乎操作更加简便一些,还可以安装tortoisegit,是一个gui界面.不过我想用习惯了 ...
- Keystore概念,Keytool工具使用
几个概念 keystore是一个密码保护的文件,用来存储密钥和证书(也就是说,keystore中存储的有两类型entries):这个文件(默认的)位于你的home目录,也就是你登录到操作系统的用户名的 ...
- Shell常用操作
1.读取配置文件中的jdbc_url参数的值($InputParamFile为待读取的目标文件绝对路径) jdbc_url=`grep "jdbc_url" $InputParam ...
- nginx简单反向代理和负载均衡(ubuntu)
nginx简单反向代理与负载均衡 环境:三台ubuntu 12.04.5 虚拟机 均装有nginx 1.1.19 以下u1(192.168.240.129) ,u2(192.168.240.13 ...
- Visual Studio 2013
1.How to hide reference counts in VS2013? Tools--> Options --> Text Editor --> All Language ...
- Navicat Premium 11.0.19中文破解版 安装
一.navicat-premium简介 它是一款可连接多种数据库的软件,具体参见官网介绍:http://www.navicat.com.cn/products/navicat-premium 二.下载 ...