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 ...
随机推荐
- ZROI CSP-S失恋测(1)
传送门 写在前面:为了保护正睿题目版权,这里不放题面,只写题解. "怎么大家一个暑假不见都变菜了啊."--蔡老板 A 考虑一个\(nk^2\)的dp,按\(w_i\)排序,则每个组 ...
- 【leetcode】1131. Maximum of Absolute Value Expression
题目如下: Given two arrays of integers with equal lengths, return the maximum value of: |arr1[i] - arr1[ ...
- vs 2010创建Windows服务定时timer程序
vs 2010创建Windows服务定时timer程序: 版权声明:本文为搜集借鉴各类文章的原创文章,转载请注明出处: http://www.cnblogs.com/2186009311CFF/p/ ...
- 8:Spring Boot Shiro记住密码
1,添加Cookie 2,添加安全管理器中 3,配置记住我, 4 ,在登录页面中加我rememberMe复选框 /** * 1.配置Cookie对象 * 记住我的cookie:rememberMe * ...
- 总结PHP缓存技术的多种方法
这里所说的数据缓存是指数据库查询PHP缓存机制,每次访问页面的时候,都会先检测相应的缓存数据是否存在,如果不存在,就连接数据库,得到数据,并把查询结果序列化后保存到文件中,以后同样的查询结果就直接从缓 ...
- 【PowerOJ1736&网络流24题】飞行员配对方案问题(最小割)
题意: n<=100,要求输出方案 思路:准备把没刷的24题从头搞一遍 输出方案的话就在增广的时候记一下另一端的编号就好 #include<bits/stdc++.h> using ...
- UVA 540 Team Queue(模拟+队列)
题目代号:UVA 540 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page ...
- Oracle Or子句
Oracle Or子句 作者:初生不惑 Oracle基础 评论:0 条 Oracle技术QQ群:175248146 在本教程中,我们来学习如何使用Oracle OR运算符来组合两个或更多的布尔表达式. ...
- cmd开启3389
如何用CMD开启3389与查看3389端口 开启 REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server / ...
- [CSP-S模拟测试]:导弹袭击(数学+凸包+单调栈)
题目背景 $Guess$准备向敌军阵地发起进攻了!$Guess$的武器是自动制导导弹.然而在机房是不允许游戏的,所以班长$XZY$对游戏界面进行了降维打击,结果... 题目描述 众所周知,环境因素对导 ...