A. Berstagram icpc(用数组模拟)

A. Berstagram

time limit per test

3 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

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

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

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

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

before the first like: [1,2,3][1,2,3];
after the first like: [1,3,2][1,3,2];
after the second like: [1,2,3][1,2,3];
after the third like: [1,2,3][1,2,3];
after the fourth like: [1,3,2][1,3,2];
after the fifth like: [3,1,2][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 nn and mm (1≤n≤1051≤n≤105, 1≤m≤4⋅1051≤m≤4⋅105) — number of posts and number of likes.

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

Output

Print nn pairs of integer numbers. The ii-th line should contain the highest (minimum) and the lowest (maximum) positions of the ii-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 11 (highest) to nn (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

用两个数组来模拟就好了

#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
 
#define sc scanf
#define ls rt << 1
#define rs ls | 1
#define Min(x, y) x = min(x, y)
#define Max(x, y) x = max(x, y)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define MEM(x, b) memset(x, b, sizeof(x))
#define lowbit(x) ((x) & -(x))
#define P2(x) ((x) * (x))
typedef long long ll;
int p[MAXN], n, m;
int max_[MAXN], min_[MAXN];
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) 
	max_[i] = min_[i] = p[i] = i, mp[i] = i;
	for (int i = 1; i <= m; i++) {
		int tmp; sc("%d", &tmp);
		if (p[1] == tmp) continue; // 第一个位置忽略
		int xi = mp[tmp]; 
		swap(p[xi], p[xi - 1]);  // 交换
		mp[tmp] = xi - 1, mp[p[xi]] = xi; 
		Min(min_[tmp], xi - 1); Max(max_[p[xi]], xi);
	}
	for (int i = 1; i <= n; i++) cout << min_[i] << " " << max_[i] << endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值