这题单用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. linux中mysql安装(配图)

    环境: 1.操作系统:CentOS release 6.8 (Final) 2.安装版本: mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz 3.下载地址:http: ...

  2. vue+muse-ui

    1.可以很好的配合vue2.0开发 2.安装: npm install  muse-ui --save 3.引入: 在main.js中加入 import Vue from 'vue' import M ...

  3. zabbix4.2配置监控TCP连接状态

    1.使用命令查看TCP连接状态 (1)过去常用命令:netstat -antp [root@ansible-control zabbix]# netstat -antp Active Internet ...

  4. C语言输入一个整数转化为字符串

    将数字转化为对应的字符,可以通过n%10+48来实现,也可以通过n%10+'0'来实现,因为‘0’的ASCII码的数值就是48 因为字符串‘0’ 对应的10进制 整数是48 字符串'9'对应的10进制 ...

  5. WPF学习笔记三之绑定

    1.绑定模式 <TextBlock Margin="10" Text="LearningHard" Name="lbtext" Fon ...

  6. 剑指offer 面试题 删除链表中重复的节点

    题目描述 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1->2->3->3->4->4->5 处理后 ...

  7. css div布局示例2(head-main-footer

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. js -- 操作sqlite数据库

    最近看到一个使用js来操作sqlite数据库的,测试了一下,具体使用的是 js操作类: https://github.com/kripken/sql.js/(sqlite js 驱动) 异步请求:ht ...

  9. 将Tomcat集成到idea中

    检查有没有成功

  10. python面试的100题(3)

    3.输入日期, 判断这一天是这一年的第几天? import datetime def dayofyear(): year = input("请输入年份: ") month = in ...