so easy(并查集+unordered_map)
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_1z1x1
\vdots⋮
z_q\quad x_qzqxq
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)的更多相关文章
- Brain Network (easy)(并查集水题)
G - Brain Network (easy) Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- 2019 ICPC 徐州网络赛 B.so easy (并查集)
计蒜客链接:https://nanti.jisuanke.com/t/41384 题目大意:给定n个数,从1到n排列,其中有q次操作,操作(1) 删除一个数字 // 操作(2)求这个数字之后第一个没有 ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 【 题目:so easy】{并查集维护一个数的下一个没有被删掉的数} 补题ING
题意:给[1,n],n个数,有两种操作: 1 x,删去x2 x,查询还未被删去的数中大于等于x的最小的数是多少. input: output: 做法:按照并查集的方法压缩路径 代码: #include ...
- SOJ4480 Easy Problem IV (并查集)
Time Limit: 3000 MS Memory Limit: 131072 K Description 据说 你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过六个人你就能够认识任 ...
- *HDU1829 并查集
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- [并查集] POJ 1611 The Suspects
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 35206 Accepted: 17097 De ...
- poj 1611:The Suspects(并查集,经典题)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 21472 Accepted: 10393 De ...
- POJ 2492 并查集扩展(判断同性恋问题)
G - A Bug's Life Time Limit:10000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- hiho_1066_并查集
题目大意 给出N个操作,每个操作可能为两种类型之一: 1. 认定两个人属于同一个组织 2. 查询两个人是否是同一个组织 要求对于每个操作类型2,给出结果,即查询的两个人是否属于同一个组织.其中,任何人 ...
随机推荐
- 记录下:nth-child在table中遇到的问题~(已解决)
首先做了一个表格,如下: <!DOCTYPE html> <html> <head> <title></title> <style t ...
- Devexpress MVC GridView / CardView (持续更新)
//获取gridview里面的combo box 显示的文本 //获取某个column在gridview的 index RightGridView.GetColumnByField("Fun ...
- Linux基本命令使用(一)
1.head -n 文件 可以查看文件前n行 tail -n 文件 可以查看文件的后n行 tail -f 文件 可以实时查看文件,比如日志在更新,就可以实时显示最后几行 ...
- [design pattern](8) Command
前言 在前面的章节中,我们介绍了单例模式,它是创建型模式的一员.今天我们来介绍一下命令模式,它是行为型模式的一员. 思考题 首先,让我们来思考下面的问题: 话说有一家遥控器公司,他想制作一款很牛逼的遥 ...
- HDU4497 GCD and LCM(数论,质因子分解)
HDU4497 GCD and LCM 如果 \(G \% L != 0\) ,那么输出 \(0\) . 否则我们有 \(L/G=(p_1^{r_1})\cdot(p_2^{r_2})\cdot(p_ ...
- ES6 暂时性死区
在ES6中,声明变量新增了两个关键字:let命令和const命令 如果在区块中存在let或者const命令时,任何变量都必须在声明之前使用,无论是区块外部的全局变量或者是区块内部的变量: /* 区块外 ...
- 使用mybatis-generator-core-1.3.2.jar根据数据库表自动生成实体
1 导入mybatis-generator-core-1.3.2.jar 2配置mbg.xml <?xml version="1.0" encoding="UTF- ...
- SQLAlcvchem
一.安装(稳定版的1.2.17) 二.一般使用(切记切记不要使用模块的名字作为项目名字,否则会出现玄学解决不了的问题------坑) #.导入SQLALchemy from sqlalchemy.ex ...
- 三、Jmeter生成HTML报告
1.执行jmeter -n -t [接口脚本地址] -l [test.jtl地址] -e -o [报告输出地址] 例如:jmeter -n -t C:\chushujin\youxinscript\j ...
- Vue创建局部组件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...