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. 【NOIP2016提高A组模拟9.9】运输妹子

    题目 小轩轩是一位非同一般的的大农(lao)场(si)主(ji),他有一大片非同一般的农田,并且坐落在一条公路旁(可以认为是数轴),在他的农田里种的东西也非同一般--不是什么水稻小麦,而是妹子. 在小 ...

  2. express中app和router的区别

      var app = express(); var router = express.Router(); 以上二者的区别是什么,什么时候用哪个最合适? 区别看下面的例子: app.js var ex ...

  3. requestAnimationFram

    window.requestAnimationFrame() 告诉浏览器——你希望执行一个动画,并且要求浏览器在下次重绘之前调用指定的回调函数更新动画.该方法需要传入一个回调函数作为参数,该回调函数会 ...

  4. ssh复制公钥成功后仍需输入密码

    1,网上说权限问题 登录流程: 被登录机器的文件权限: //用户权限 chmod 700 /home/username //.ssh文件夹权限 chmod 700 ~/.ssh/ // ~/.ssh/ ...

  5. python3.5-tensorflow-keras 安装

    cpu centos FROM centos:7 MAINTAINER yon RUN yum -y install make wget \ && wget -O /etc/yum.r ...

  6. 织梦DedeCms技术资料

    Dedecms调用文章发布时间的方法 11-20 样式 ([field:pubdate function='strftime("%m-%d",@me)'/]) May 15, 20 ...

  7. Python文件对象方法

    使用open()函数创建一个文件对象,这里是可以在这个对象上调用的函数的列表 - 编号 方法名称 描述 1 file.close() 关闭文件,无法读取或写入关闭的文件. 2 file.flush() ...

  8. es之路由:进一步提高Elasticsearch的检索效率(适用大规模数据集)

    1:一条数据是如何落地到对应的shard上的 当索引一个文档的时候,文档会被存储到一个主分片中. Elasticsearch 如何知道一个文档应该存放到哪个分片中呢? 首先这肯定不会是随机的,否则将来 ...

  9. oracle备份和还原

    用exp命令即可完成,但要看具体的备份方式. 1. 导出一个完整数据库 exp system/manager file=bible_db log=dible_db full=y 2. 导出数据库定义而 ...

  10. bash中的set, env, export unset的区别

    参考这篇文章很好 参考这篇文章2 -------------------------- == set显示的是当前shell的变量, 不同的shell, 它的私有变量是不同的 env是显示用户的变量, ...