洛谷P3369 【模板】普通平衡树(STL做法:vectormultiset)
problem
solution1 - AC
- vector可以AC。lower_bound找第一个大于等于x的,upper_bound找第一个大于x的。
#include<bits/stdc++.h>
using namespace std;
int main(){ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int T; cin>>T;vector<int>a;while(T--){int op, x; cin>>op>>x;if(op==1){a.insert(upper_bound(a.begin(),a.end(),x),x);}else if(op==2){a.erase(lower_bound(a.begin(),a.end(),x));}else if(op==3){cout<<lower_bound(a.begin(),a.end(),x)-a.begin()+1<<endl;}else if(op==4){cout<<a[x-1]<<endl;}else if(op==5){cout<<*--lower_bound(a.begin(),a.end(),x)<<endl;}else{cout<<*upper_bound(a.begin(),a.end(),x)<<endl;}}return 0;
}
solution2 - WA
- multiset,不知道为啥WA一个点,还有一些TLE。
#include<bits/stdc++.h>
using namespace std;
multiset<int>se;
int main(){ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int T; cin>>T;while(T--){int op, x; cin>>op>>x;if(op==1){se.insert(lower_bound(se.begin(),se.end(),x),x);}else if(op==2){se.erase(lower_bound(se.begin(),se.end(),x));}else if(op==3){cout<<distance(se.begin(),se.upper_bound(x))<<"\n";}else if(op==4){multiset<int>::iterator it =se.begin();advance(it,x-1);cout<<*it<<"\n";}else if(op==5){cout<<*--lower_bound(se.begin(),se.end(),x)<<endl;}else{cout<<*upper_bound(se.begin(),se.end(),x)<<endl;}}return 0;
}
测试点6调试如下:看了一下有好几个位置都是比std多了1,但是不知道为啥
洛谷P3369 【模板】普通平衡树(STL做法:vectormultiset)相关推荐
- 【洛谷P3369】普通平衡树(splay)
emmmmm直接丢代码了 #include<iostream> #include<cstdio> #include<cstring> #include<str ...
- 专题·树链剖分【including 洛谷·【模板】树链剖分
初见安~~~终于学会了树剖~~~ [兴奋]当初机房的大佬在学树剖的时候我反复强调过:"学树剖没有前途的!!!" 恩.真香. 一.重链与重儿子 所谓树剖--树链剖分,就是赋予一个链的 ...
- 洛谷·【模板】点分树 | 震波【including 点分树
初见安-这里是传送门:洛谷P6329 [模板]点分树 | 震波 一.点分树 其实你会点分治的话,点分树就是把点分治时的重心提出来重新连城一棵树. 比如当前点是u,求出子树v的重心root后将root与 ...
- 【洛谷P3369】 (模板)普通平衡树
https://www.luogu.org/problemnew/show/P3369 Splay模板 1 #include<iostream> 2 #include<cstdio& ...
- 洛谷P3369 普通平衡树
刚学平衡树,分别用了Splay和fhq-treap交了一遍. 这是Splay的板子,貌似比较短? Splay #include <iostream> #include <cstdio ...
- 洛谷.3919.[模板]可持久化数组(可持久化线段树/平衡树)
题目链接 //利用先前的根节点建树 想一下不难写. #include <cstdio> #include <cctype> //#define gc() getchar() # ...
- 洛谷.4897.[模板]最小割树(Dinic)
题目链接 最小割树模板.具体见:https://www.cnblogs.com/SovietPower/p/9734013.html. ISAP不知为啥T成0分了.. Dinic: //1566ms ...
- 强连通分量:洛谷P3387 模板:缩点
传送门 顾名思义,模板awa #include <cstdio> #include <cstring> #include <cmath> #include < ...
- 【后缀数组】洛谷P3809模板题
题目背景 这是一道模板题. 题目描述 读入一个长度为 n n n 的由大小写英文字母或数字组成的字符串,请把这个字符串的所有非空后缀按字典序从小到大排序,然后按顺序输出后缀的第一个字符在原串中的位置. ...
最新文章
- matlab ros 手势识别,使用MATLAB读取分析ros记录的.bag文件
- Java并发编程之ThreadLocal源码分析
- 使用LitePal操作数据库(CRUD增删改查) 项目已上传GitHub
- 前OnePlus视觉设计师蔡孝永:视觉设计师都在想些什么?
- 2007年度最具投资价值100强网站揭晓——博客园榜上有名
- 微软官方office2010使用技巧宝典视频免费下载
- 17种常用的JS正则表达式 非负浮点数 非负正数
- RUNOOB python练习题33 使用join方法实现用逗号分隔列表
- [论文翻译] Medical Matting: A New Perspective on Medical Segmentation with Uncertainty
- NSData与UIImage之间的转换
- IM消息重试机制Java实现_消息的重试机制的设计思路
- 安装Keil uVision5 破解失败
- 【ubuntu如何卸载mysql(ubuntu卸载mysql的具体方法)】
- 酒店客房卫生打扫步骤及重点
- 昂达平板不能开机刷机_昂达平板刷机V811 V701 V702 V711刷错固件刷回方法
- 自己搭建无线音乐服务器,建立自己的音乐库 Aurender ACS10 音乐服务器
- word插入图片之后只显示一部分的解决方法
- 你知道哪六种传统早餐不能吃吗?
- jdk,jre,jvm的包含关系
- powershell中文乱码解决办法
热门文章
- Python 绘图利器 —— ggplot
- 为hadoop集群安装mapreduce
- sqlserver management studio 2014 升级2016_画质提升音质更佳:Insta360影石ONE R迎来最强升级...
- python与java前景-Java和Python现在都很热门,哪个更有前途?
- python爬虫教程-Python教父|廖雪峰老师官方爬虫教程,13个案例带你全面入门!
- python-Python教程
- python 代码命令大全-Linux命令大全
- python 下载文件-python实现下载文件的三种方法_python
- 专科python应届生工资多少-应届生学Python年薪30万,秘诀是什么?
- 语音识别软件、语音识别平台和语音识别技术