stl(set或map)
https://nanti.jisuanke.com/t/41384
There are nnn points in an array with index from 111 to nnn, and there are two operations to those points.
1: 1 x1 \ x1 x marking the point xxx is not available
2: 2 x2 \ x2 x query for the index of the first available point after that point (including xxx itself) .
Input
nqn\quad qnq
z1x1z_1 \quad x_1z1x1
⋮\vdots⋮
zqxqz_q\quad x_qzqxq
qqq is the number of queries, zzz is the type of operations, and xxx is the index of operations. 1≤x<n<1091≤x<n<10^91≤x<n<109, 1≤q<1061 \leq q<10^6 1≤q<106 and zzz is 111 or 222
Output
Output the answer for each query.
样例输入
5 3
1 2
2 2
2 1
样例输出
3
1 题意:给出1-n,q个操作
第一个操作(1):将某个值标记为不可用;
第二个操作(2):输出该值以后的第一个有用值。
神奇的编译器:c++14超时,c++11就过辽。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
using namespace std; #define mem(a) memset(a,0,sizeof(a))
#define ll long long
const int maxn = ;
int n,q,a,b;
set<int>s;
int solve()
{
while(b <= n)
{
if(s.find(b) != s.end())
b++;
else return b;
}
return -;
} int main()
{
scanf("%d%d",&n,&q);
for(int i = ; i < q; i++)
{
scanf("%d%d",&a,&b);
if(a == )
{
s.insert(b);
}
else
{
printf("%d\n",solve());
// 也可以s.count判断是否存在。
/*while(s.count(b))
{
b++;
}
printf("%d\n" , b);*/ }
}
return ;
}
map会超时要用unordered_map
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <unordered_map>
using namespace std; #define mem(a) memset(a,0,sizeof(a))
#define ll long long
const int maxn = ;
int n,q,a,b; int main()
{
unordered_map<int , int>mp;
scanf("%d%d",&n,&q);
for(int i = ; i < q; i++)
{
scanf("%d%d",&a,&b);
if(a == )
{
mp[b] = - ;
}
else
{
while(mp[b] == -) b++ ;
printf("%d\n" , b);
}
}
return ;
}
stl(set或map)的更多相关文章
- UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- STL中的map、unordered_map、hash_map
转自https://blog.csdn.net/liumou111/article/details/49252645 在之前使用STL时,经常混淆的几个数据结构,特别是做Leetcode的题目时,对于 ...
- [知识点]C++中STL容器之map
UPDATE(20190416):写完vector和set之后,发现不少内容全部引导到map上了……于是进行了一定的描述补充与更正. 零.STL目录 1.容器之map 2.容器之vector 3.容器 ...
- STL 中的map 与 hash_map的理解
可以参考侯捷编著的<STL源码剖析> STL 中的map 与 hash_map的理解 1.STL的map底层是用红黑树存储的,查找时间复杂度是log(n)级别: 2.STL的hash_ma ...
- STL中的map和unordered_map
STL中的map和unordered_map map 头文件:#include 原理:std::map的内部实现了一颗红黑树,有对其键值进行排序的功能,所以map是一个有序的容器,map中的每一个元素 ...
- Linux环境下stl库使用(map)
例子1: testMap.cpp #include <string.h> #include <iostream> #include <map> #include & ...
- stl中的map数据类型
1.1 STL map 1.1.1 背景 关联容器使用键(key)来存储访问读取元素,而顺序容器则通过元素在容器中的位置存储和访问元素. 常见的顺序容器有:vector.list.deque.stac ...
- 【STL学习】map&set
技术不只是我的工作,也是我的生活,以后的博客中会穿插一些个人的喜悦.愤怒或者感悟,希望大家能够接受. 我所有的一切,比我技术更好的怕是我的脸皮了,昨天收到京东面试没有通过的消息,喊了几句“我好悲伤啊” ...
- STL中关于map和set的四个问题?
STL map和set的使用虽不复杂,但也有一些不易理解的地方,如: 为何map和set的插入删除效率比用其他序列容器高? 或许有得人能回答出来大概原因,但要彻底明白,还需要了解STL的底层数据结构. ...
- C++标准模板库(STL)之Map
1.Map的常用用法 map:映射.可以将任何基本类型,结构体,STL容器映射到任何基本类型包括容器. 使用map,需要加map的头文件,#include<map>和using names ...
随机推荐
- httprunner
https://cn.httprunner.org/quickstart/ httprunner官方 https://testerhome.com/opensource_projects/httpru ...
- uoj207 共价大爷游长沙 子树信息 LCT + 随机化 + 路径覆盖
题目传送门 http://uoj.ac/problem/207 题解 如果是一棵静态的树,有一个非常容易想到的算法:统计一下目前的每一个条边被几条路径经过,如果 \(x\) 到 \(y\) 的边的这个 ...
- python基本数据类型常用方法
python基本数据类型 1.整型 1.1 int 1.2 bit_lenght # 当前数字的二进制位数,至少用n位表示 r = age.bit_length() >>> a = ...
- KCF跟踪算法
参考:https://www.cnblogs.com/YiXiaoZhou/p/5925019.html 参考:https://blog.csdn.net/shenxiaolu1984/article ...
- 关闭DELPHI 欢迎页
打开注册表 HKEY_CURRENT_USER\Software\Embarcadero\BDS\20.0\Known IDE Packages(20.0为版本号) 将$(BDS)\Bin\start ...
- python学习_day1
简单的输入与输出 python3.x输入 用内置函数input(),返回的数据类型是string,输出用print() 查看数据类型 用type方法 例如 a = int(input('请输入:')) ...
- CSS3实现三角形和对话框
这是最终实现的效果,类似于微信对话框的样式. 分析一下这个对话框的结构,由一个小三角形和一个长方形构成.长方形很容易就可以实现,重点是如何用CSS3做出一个小三角形. 一.如何生成一个三角形 总结: ...
- HTML和CSS实现的透明登录框效果
实现代码 HTML部分 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- find查找特殊权限用法
find查找特殊权限的用法 find選項與參數: 3. 與檔案權限及名稱有關的參數: -name filename:搜尋檔案名稱為 filename 的檔案: -size [+-]SIZE:搜尋比 S ...
- 建立起BI的支撑团队
Bobby Luo 罗如意(18907295660@189.cn) 2011年7月 http://weibo.com/cquptvlry 电子商务中的BI应用初探 系统架构 对整个数据仓库的架构进行规 ...