The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 B so easy
题目链接: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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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. ...
- 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 ...
- 计蒜客 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 ...
- 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 ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019
A:Who is better? 题目链接:https://nanti.jisuanke.com/t/41383 题意: 类似于有N个石子,先手第一次不能拿完,每次后手只能拿 1 到 前一次拿的数量* ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 E. XKC's basketball team
题目链接:https://nanti.jisuanke.com/t/41387 思路:我们需要从后往前维护一个递增的序列. 因为:我们要的是wi + m <= wj,j要取最大,即离i最远的那个 ...
随机推荐
- 面向对象核心技术(java)
一.类的封装详解 在“面向对象编程基础(java)”的时候讲过,封装是面向对象编程的核心思想.同时我们也知道类是载体,只不过我们把对象的属性和行为封装在载体中. 现我们用封装的方式来实现,一个顾客去一 ...
- xftp连接centos7
1.下载xftp文件,并正常进行安装 2.安装好之后运行,并新建会话,此时可见如下界面: 注意: 名称,可随便输入,自己能看懂是什么就行 主机,输入当前Linux服务器的ip(如何获取服务器 ...
- 并发系列64章(TPL 数据流)第七章
前言 什么是TPL?全称:transmission control protocol 传输层对应于OSI七层参考模型的传输层,它提供两种端到端的通信服务. 然后思维方式回到为什么有这个TPL 数据流上 ...
- java消除 list重复值及交集,并集,差集
消除 list重复值 Java代码 public void removeDuplicate(List list) { HashSet h = new HashSet(list); list.clea ...
- Python 获取任意周期开盘日
import json import requests import datetime import tushare as ts cal_dates = ts.trade_cal() today=da ...
- 1 - Apache HttpClient 简单使用
Apache HttpClient 是Apache 开源的实现Http协议的java开源库. HttpClien 是客户端的HTTP通信实现库,实现HTTP GET 和POST请求,获取响应内容. A ...
- PAS
一.概念 二.安装 打开Delphi,在主菜单上选择Component,单击Install Component,出现图所示的对话框.有两个选择,装到已经存在的包里面和装到新的包里面.我们选择后者,单击 ...
- 抠脚大叔如何改变性别,Python实现变声器功能
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 乔柯 PS:如有需要Python学习资料的小伙伴可以加点击下方链接 ...
- 定位new表达式与显式调用析构函数
C++的核心理念之一是RAII,Resource Acquisition Is Initialization,资源获取即初始化.资源有很多种,内存.互斥锁.文件.套接字等:RAII可以用来实现一种与作 ...
- Daily Scrum 1/11/2016
Zhaoyang & Minlong: Took and edited the video which introduced our APP. Yandong: Summarized bugs ...