题目链接:https://nanti.jisuanke.com/t/41384

这题暴力能过,我用的是并查集的思想,这个题的数据是为暴力设置的,所以暴力挺快的,但是当他转移的点多了之后,我觉得还是我这种方法更好一点。注意这里一定要用内部是hash的unordered_map 做,因为查询为o(1)

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <unordered_map>
#include <cmath>
#include <map>
#define N 100010
using namespace std;
typedef long long ll;
unordered_map<int,int>fa;
int n,q;
int get(int x)
{
if(fa.count(x)==0) return x;
fa[x]=get(fa[x]);
}
int main()
{
scanf("%d%d",&n,&q);
// for(int i=1;i<=n+1;i++)fa[i]=i;
int a,b;
while(q--)
{
scanf("%d%d",&a,&b);
if(a==1)
fa.insert(make_pair(b,b+1));
else
{
printf("%d\n",get(b));
}
}
}

The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 B so easy的更多相关文章

  1. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 K题 center

    You are given a point set with nn points on the 2D-plane, your task is to find the smallest number o ...

  2. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 XKC's basketball team

    XKC , the captain of the basketball team , is directing a train of nn team members. He makes all mem ...

  3. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 D Carneginon

    Carneginon was a chic bard. But when he was young, he was frivolous and had joined many gangs. Recen ...

  4. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 C Buy Watermelon

    The hot summer came so quickly that Xiaoming and Xiaohong decided to buy a big and sweet watermelon. ...

  5. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 A Who is better?

    A After Asgard was destroyed, tanker brought his soldiers to earth, and at the same time took on the ...

  6. 计蒜客 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 ...

  7. 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 ...

  8. The Preliminary Contest for ICPC Asia Xuzhou 2019

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

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

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

随机推荐

  1. 微服务框架-Spring Cloud

    Spring Cloud入门 微服务与微服务架构 微服务架构是一种新型的系统架构.其设计思路是,将单体架构系统拆分为多个可以相互调用.配合的独立运行的小程序.这每个小程序对整体系统所提供的功能就称为微 ...

  2. AJ学IOS(50)多线程网络之GCD简单介绍(任务,队列)

    AJ分享,必须精品 GCD简单介绍 1.什么是GCD? 全称是Grand Central Dispatch,可译为“牛逼的中枢调度器” 纯C语言,提供了非常多强大的函数 2.GCD的优势 GCD是苹果 ...

  3. linux常用命令整理(一)

    1.sort(排序) 典型例题:sort -t: -k3n /etc/passwd 以冒号为分隔符根据第三个域的数字大小进行排序(默认分隔符是空格) 2.uniq(去除文件中的连续重复行) 典型例题: ...

  4. 也谈如何实现bind、apply、call

    也谈如何实现bind.apply.call 我们知道,JavaScript的bind.apply.call是三个非常重要的方法.bind可以返回固定this.固定参数的函数包装:apply和call可 ...

  5. J - The sum problem

    Given a sequence 1,2,3,......N, your job is to calculate all the possible sub-sequences that the sum ...

  6. div3--C. Pipes

    题目链接:https://codeforces.com/contest/1234/problem/C 题目大意:根据规则,判断是否可以从左上走到右下,1,2,3,4,5,6分别对应题干给的图片,所以1 ...

  7. 【LeetCode】 99. Recover Binary Search Tree [Hard] [Morris Traversal] [Tree]

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  8. PHP函数:func_num_args

    func_num_args()  - 返回传递给函数的参数数量. 说明: func_num_args ( void ) : int 参数: 无 返回值: 返回传入当前用户定义函数的参数数量. 参考链接 ...

  9. java中的模运算规则

    取模运算定义 如果a和d是两个自然数,d非零,可以证明存在两个唯一的整数 q 和 r,满足 a = qd + r 且0 ≤ r < d.其中,q 被称为商,r 被称为余数. 运算实例 java模 ...

  10. Python 实用冷门知识整理

    1.print 打印带有颜色的信息 大家知道 Python 中的信息打印函数 print,一般我们会使用它打印一些东西,作为一个简单调试. 但是你知道么,这个 Print 打印出来的字体颜色是可以设置 ...