There are nn points in an array with index from 11 to nn, and there are two operations to those points.

1: 1 \ x1 x marking the point xx is not available

2: 2 \ x2 x query for the index of the first available point after that point (including xx itself) .

Input

n\quad qnq

z_1 \quad x_1z1​x1​

\vdots⋮

z_q\quad x_qzq​xq​

qq is the number of queries, zz is the type of operations, and xx is the index of operations. 1≤x<n<10^91≤x<n<109, 1 \leq q<10^61≤q<106 and zz is 11 or 22

Output

Output the answer for each query.

样例输入复制

5 3
1 2
2 2
2 1

样例输出复制

3
1
#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5 + ;
unordered_map<int, int> fa; int findfa(int x) {
if (!fa.count(x)) return x;
return fa[x] = findfa(fa[x]);
} int main() {
int n, q;
scanf("%d %d", &n, &q);
int op, x;
while (q--) {
scanf("%d %d", &op, &x);
if (op == ) {
fa[x] = findfa(x + );
} else {
int ans = findfa(x);
if (ans > n) ans = -;
printf("%d\n", ans);
}
}
return ;
}

so easy(并查集+unordered_map)的更多相关文章

  1. Brain Network (easy)(并查集水题)

    G - Brain Network (easy) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  2. 2019 ICPC 徐州网络赛 B.so easy (并查集)

    计蒜客链接:https://nanti.jisuanke.com/t/41384 题目大意:给定n个数,从1到n排列,其中有q次操作,操作(1) 删除一个数字 // 操作(2)求这个数字之后第一个没有 ...

  3. The Preliminary Contest for ICPC Asia Xuzhou 2019 【 题目:so easy】{并查集维护一个数的下一个没有被删掉的数} 补题ING

    题意:给[1,n],n个数,有两种操作: 1 x,删去x2 x,查询还未被删去的数中大于等于x的最小的数是多少. input: output: 做法:按照并查集的方法压缩路径 代码: #include ...

  4. SOJ4480 Easy Problem IV (并查集)

    Time Limit: 3000 MS Memory Limit: 131072 K Description 据说 你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过六个人你就能够认识任 ...

  5. *HDU1829 并查集

    A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  6. [并查集] POJ 1611 The Suspects

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 35206   Accepted: 17097 De ...

  7. poj 1611:The Suspects(并查集,经典题)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21472   Accepted: 10393 De ...

  8. POJ 2492 并查集扩展(判断同性恋问题)

    G - A Bug's Life Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  9. hiho_1066_并查集

    题目大意 给出N个操作,每个操作可能为两种类型之一: 1. 认定两个人属于同一个组织 2. 查询两个人是否是同一个组织 要求对于每个操作类型2,给出结果,即查询的两个人是否属于同一个组织.其中,任何人 ...

随机推荐

  1. electron-vue ipcRenderer.on() 调用多次

    methods: { isSave (ev) { this.localFileUrl = ev.localFileUrl // 本地的路径 ipcRenderer.send('save-dialog' ...

  2. YOLO_v1

    目标检测算法可以分为两类: 一类是基于region proposal的R-CNN系列算法(R-CNN,Fast R-CNN, Faster R-CNN),它们是two-stage的.要先使用启发式方法 ...

  3. jenkins 管理员密码重置

    jenkins管理员 admin的密码忘记怎么重置呢? 修改admin的加密密码为123456的加密密码 #jbcrypt:$2a$10$MiIVR0rr/UhQBqT.bBq0QehTiQVqgNp ...

  4. sqli-labs(28a)

    0X01构造闭合 爆字段数 /?id=') order by 1%23 ?id=') order by 5%23 偷看一下源码 就只过滤了union select 闭合') 那我们来尝试一下 0X02 ...

  5. crontab定时调度shell脚本

    本人最近要用crontab做一个定时调度任务,调一个启动脚本去执行jar包,并给main方法传一个日期参数. Linux系统:CentOS7 输入: crontab -e 在里面编写: SHELL=/ ...

  6. 解决img标签与其它标签间隙问题?

    解决img标签间距问题 关于img标签间距问题:多个img之间有间距,包含img标签的div之间有间距 代码如下: <!DOCTYPE html> <html> <hea ...

  7. python数据类型之 元祖、列表字典

    Python中元祖,列表,字典   Python中有3种內建的数据结构:列表.元祖和字典: 1.列表 list是处理一组有序项目的数据结构,即你可以在一个列表中存储一个序列的项目. 列表中的项目应该包 ...

  8. linux日常---2、lamp.sh安装lamp环境中的linux操作

    linux日常---2.lamp.sh安装lamp环境中的linux操作 一.总结 一句话总结: 学不如用,学一百遍还不如真正多用几遍的来的效果好 1.linux下查看进程命令? ps 常用 ps - ...

  9. JWT原理和使用

    jwt JSON Web Tokens,是一种开发的行业标准RFC 7519,用于安全的表示双方之间的声明.目前,jwt广泛的用在系统的用户认证方面,特别是前后端分离项目. 1.jwt认证流程 在项目 ...

  10. Flink数据流图的生成----简单执行计划的生成

    Flink的数据流图的生成主要分为简单执行计划-->StreamGraph的生成-->JobGraph的生成-->ExecutionGraph的生成-->物理执行图.其中前三个 ...