这题单用map过不了,太慢了,所以改用unordered_map,对于前面删除的点,把它的父亲改成,后面一位数的父亲,初始化的时候,map里是零,说明它的父亲就是它本身,最后输出答案的时候,输出每一位数的父亲就好了。

下面的程序可能在windows本地编译过不了,头文件放在下面。

#include <bits/stdc++.h>
using namespace std; unordered_map<int,int>mp; int find(int x)
{
if (mp[x]==0) {
return x;
}
return mp[x]=find(mp[x]);
} int main()
{
int n,q,op,num;
scanf("%d%d",&n,&q);
for (int i=0;i<q;i++) {
scanf("%d%d",&op,&num);
if (op==1) {
mp[num]=find(num+1);
}
else {
printf("%d\n",find(num));
}
}
return 0;
}
/*
10 10
1 5
1 6
1 8
1 9
1 7
2 5
*/
#if(__cplusplus == 201103L)
#include <unordered_map>
#include <unordered_set>
#else
#include <tr1/unordered_map>
#include <tr1/unordered_set>
namespace std
{
using std::tr1::unordered_map;
using std::tr1::unordered_set;
}
#endif
using namespace std; unordered_map<int,int>mp;

The Preliminary Contest for ICPC Asia Xuzhou 2019 B. so easy (unordered_map+并查集)的更多相关文章

  1. 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)

    query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...

  2. The Preliminary Contest for ICPC Asia Xuzhou 2019 E XKC's basketball team [单调栈上二分]

    也许更好的阅读体验 \(\mathcal{Description}\) 给n个数,与一个数m,求\(a_i\)右边最后一个至少比\(a_i\)大\(m\)的数与这个数之间有多少个数 \(2\leq n ...

  3. The Preliminary Contest for ICPC Asia Xuzhou 2019

    A:Who is better? 题目链接:https://nanti.jisuanke.com/t/41383 题意: 类似于有N个石子,先手第一次不能拿完,每次后手只能拿 1 到 前一次拿的数量* ...

  4. The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team

    题目链接:https://nanti.jisuanke.com/t/41387 思路:我们需要从后往前维护一个递增的序列. 因为:我们要的是wi + m <= wj,j要取最大,即离i最远的那个 ...

  5. 计蒜客 41387.XKC's basketball team-线段树(区间查找大于等于x的最靠右的位置) (The Preliminary Contest for ICPC Asia Xuzhou 2019 E.) 2019年徐州网络赛

    XKC's basketball team XKC , the captain of the basketball team , is directing a train of nn team mem ...

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

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

  7. G.Colorful String(The Preliminary Contest for ICPC Asia Xuzhou 2019)

    https://nanti.jisuanke.com/t/4 #include <bits/stdc++.h> using namespace std; ,; typedef unsign ...

  8. E.XKC's basketball team(The Preliminary Contest for ICPC Asia Xuzhou 2019)

    https://nanti.jisuanke.com/t/41387 解: 离散化+线段树. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); ...

  9. A.Who is better?(The Preliminary Contest for ICPC Asia Xuzhou 2019)

    https://nanti.jisuanke.com/t/41383 解: 斐波那契博弈+中国剩余定理. #include <bits/stdc++.h> using namespace ...

随机推荐

  1. bugku 想蹭网先解开密码

    首先下载文件 然后 创建密码字典:使用命令 crunch 11 11 -t 1391040%%%% -o password.txt 爆破:使用命令 aircrack-ng -a2 所下载文件的地址 - ...

  2. Django中content-type组件的使用

    content-type组件 ContentType是Django的内置的一个应用,可以追踪项目的所有APP和model的对应关系,并记录在ContentTpe表中,当我们的项目做数据迁移后,会有很多 ...

  3. Oracle客户端安装及下载地址

    一.下载 http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-win64soft-094461 ...

  4. 训练20191007 2017-2018 ACM-ICPC Latin American Regional Programming Contest

    2017-2018 ACM-ICPC Latin American Regional Programming Contest 试题地址:http://codeforces.com/gym/101889 ...

  5. http接口性能测试工具

    一. http_load 程序非常小,解压后也不到100K.http_load以并行复用的方式运行,用以测试web服务器的吞吐量与负载. 但是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一 ...

  6. IntelliJ IDEA 2017.3尚硅谷-----创建动态的 Java Web

  7. SpringBoot获取http请求参数的方法

    SpringBoot获取http请求参数的方法 原文:https://www.cnblogs.com/zhanglijun/p/9403483.html 有七种Java后台获取前端传来参数的方法,稍微 ...

  8. AC3 overview

    1.AC3 encode overview AC3 encoder的框图如下: AC3在频域采用粗量化(coarsely quantizing)来获取较高的压缩率. 1).输入PCM 经过MDCT变换 ...

  9. mysql5.7导出数据提示--secure-file-priv选项问题的解决方法

    mysql可使用 into outfile 参数把表中数据导出到csv,例如可用以下命令把user表的数据导出到user.csv select * from user into outfile '/t ...

  10. Oracle空表的分配segment

      1.查询相关参数deferred_segment_creation select * from v$parameter where name='deferred_segment_creation' ...