A. Berstagram

Polycarp recently signed up to a new social network Berstagram. He immediately published n posts there. He assigned numbers from 1 to n to all posts and published them one by one. So, just after publishing Polycarp's news feed contained posts from 1 to n — the highest post had number 1, the next one had number 2, ..., the lowest post had number n.

After that he wrote down all likes from his friends. Likes were coming consecutively from the 1-st one till the m-th one. You are given a sequence a1,a2,…,am (1≤aj≤n), where aj is the post that received the j-th like.

News feed in Berstagram works in the following manner. Let's assume the j-th like was given to post aj. If this post is not the highest (first) one then it changes its position with the one above. If aj is the highest post nothing changes.

For example, if n=3, m=5 and a=[3,2,1,3,3], then Polycarp's news feed had the following states:

before the first like: [1,2,3];
after the first like: [1,3,2];
after the second like: [1,2,3];
after the third like: [1,2,3];
after the fourth like: [1,3,2];
after the fifth like: [3,1,2].
Polycarp wants to know the highest (minimum) and the lowest (maximum) positions for each post. Polycarp considers all moments of time, including the moment "before all likes".

Input
The first line contains two integer numbers n and m (1≤n≤105, 1≤m≤4⋅105) — number of posts and number of likes.

The second line contains integers a1,a2,…,am (1≤aj≤n), where aj is the post that received the j-th like.

Output
Print n pairs of integer numbers. The i-th line should contain the highest (minimum) and the lowest (maximum) positions of the i-th post. You should take into account positions at all moments of time: before all likes, after each like and after all likes. Positions are numbered from 1 (highest) to n (lowest).

Examples
input

Copy
3 5
3 2 1 3 3
output

Copy
1 2
2 3
1 3
input

Copy
10 6
7 3 5 7 3 6
output

Copy
1 2
2 3
1 3
4 7
4 5
6 7
5 7
8 8
9 9
10 10
思路:定义两个数组,分别存放不断改变的当前数和某数的位置。然后模拟。QAQ 
#include<bits/stdc++.h>

using namespace std;
#define int long long
#define N 1000500
struct str{
int L,R;
}st[N];
int arr[N];
int a[N];// 当前的数
int b[N];// 某数的位置
signed main(){
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++){
st[i].L=i;
st[i].R=i;
a[i]=i;
b[i]=i;
}
for(int i=;i<=m;i++)
scanf("%lld",&arr[i]);
for(int i=;i<=m;i++){
if(b[arr[i]]!=){
int weizhi=b[arr[i]];
int temp=a[weizhi-];//前面一个数
swap(a[weizhi],a[weizhi-]);
b[arr[i]]=b[arr[i]]-;
b[temp]=b[temp]+;
st[arr[i]].L=min(st[arr[i]].L,b[arr[i]]);
st[arr[i]].R=max(st[arr[i]].R,b[arr[i]]);
st[temp].L=min(st[temp].L,b[temp]);
st[temp].R=max(st[temp].R,b[temp]);
}
}
for(int i=;i<=n;i++){
cout<<st[i].L<<" "<<st[i].R<<'\n';
}
return ;
}
 

2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)【A题 类型好题】的更多相关文章

  1. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules) D. Firecrackers (贪心,二分)

    题意:有个长度为\(n\)的监狱,犯人在位置\(a\),cop在位置\(b\),你每次可以向左或者向右移动一个单位,或者选择不动并在原地放一个爆竹\(i\),爆竹\(i\)在\(s[i]\)秒后爆炸, ...

  2. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules) C. Berpizza (STL)

    题意:酒吧里有两个服务员,每个人每次都只能服务一名客人,服务员2按照客人进酒吧的顺序服务,服务员3按照客人的钱来服务,询问\(q\),\(1\)表示有客人进入酒吧,带着\(m\)块钱,\(2\)表示询 ...

  3. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest

    目录 Contest Info Solutions A. Berstagram B. The Feast and the Bus C. Trip to Saint Petersburg E. The ...

  4. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  5. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  6. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  7. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  8. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A 思路: 贪心,每次要么选两个最大的,要么选三个,因为一个数(除了1)都可以拆成2和3相加,直到所有的数都相同就停止,这时就可以得到答案了; C: 二分+bfs,二分答案,然后bfs找出距离小于等于 ...

  9. 2014-2015 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    I. Sale in GameStore(贪心) time limit per test 2 seconds memory limit per test 512 megabytes input sta ...

随机推荐

  1. 【坑】解决maven管理SSM中mybatis的mapper文件扫描失败的问题

    文章目录 前言 改进方式来替换原始的使用方式 后记 好久没有写博客了,11月底来到公司实习,上个月写个小demo,趁此回顾下SSM,今天将最近的积累记录下: 前言 在学习 mybatis 的时候,都知 ...

  2. Excel逻辑运算函数

    Excel逻辑运算函数 1.FALSE和TRUE的使用 ​ 筛选出表中salary>6.gender为男.age>28至少满足这三个条件中的两个的数据 1.依次使用:=C2>6.=D ...

  3. 二、点亮LED

    接着上一章,本章来实现控制LED的亮灭操作: 一.驱动框架 #include <linux/fs.h> #include <linux/init.h> /* 定义文件内私有结构 ...

  4. Codeforces 666E Forensic Examination(广义后缀自动机+线段树合并)

    将所有串(包括S)放一块建SAM.对于询问,倍增定位出该子串所在节点,然后要查询的就是该子串在区间内的哪个字符串出现最多.可以线段树合并求出该节点在每个字符串中的出现次数. #include<b ...

  5. SpringMVC 出现 406(Not Acceptable)

    首先,需要清楚,http state 406代表什么意思: 406是HTTP协议状态码的一种,表示无法使用请求的特性来响应请求的网页.一般指客户端浏览器不接受所请求页面的MIME类型. 出现这样的错误 ...

  6. SQL优化中的重要概念:事务

    原文:SQL优化中的重要概念:事务 sql 优化和事务有关系? 从表面上看,让sql跑的更快,似乎和事务这个概念没什么联系,但是关系数据库中最重要的2个概念就是 关系.事务. 关系,对应到sql中,是 ...

  7. 九、小程序 Redux详解与在小程序中怎么使用(action和reducers)

    什么是Redux ​ Redux我们可以把它理解成一个状态管理器,可以把状态(数据)存在Redux中,以便增.删.改.例如: 从服务器上取一个收藏列表,就可以把取回来的列表数据用Redux管理,多个页 ...

  8. myeclipse 出现换行符和空格符 解决方案 换行出现乱码

    请参看百度经验 https://jingyan.baidu.com/article/acf728fd2639e4f8e510a399.html myeclipse 2014 自定义视图Customiz ...

  9. SSL Virtual Servers

    SSL Virtual Servers 来源 https://www.carlstalhood.com/ssl-virtual-servers-netscaler-12/ SSL Virtual Se ...

  10. Nginx与负载均衡

    Nginx,首先是一款轻量级的Web服务器,其特点是占有内存少,并发能力强,大厂用户有:百度.新浪.网易.腾讯等.其次,它是一款反向代理服务器:第三,它还是一款电子邮件(IMAP/POP3)代理服务器 ...