OI Problems   关于

#ktzagy. Messenger Simulator

时间限制:3 s       空间限制:256 MiB       标签: CodeForces 缺题解 

算法难度等级:0       思维难度等级:0       实现难度等级:0


本题来源于:Educational Codeforces Round 80 (Rated for Div. 2) Problem E

题面翻译

一个长度为 nn 的好友列表,自上而下依次是 1n1 \sim n,你依次收到了 mm 条消息,第 ii 条消息是 aia_i 发来的,这时 aia_i 会跳到会话列表的最上面,其它的按原顺序顺延,求 1n1 \sim n 每个好友最靠上的位置和最靠下的位置。

题目描述

Polycarp is a frequent user of the very popular messenger. He's chatting with his friends all the time. He has nn friends, numbered from 11 to nn .

Recall that a permutation of size nn is an array of size nn such that each integer from 11 to nn occurs exactly once in this array.

So his recent chat list can be represented with a permutation pp of size nn . p1p_1 is the most recent friend Polycarp talked to, p2p_2 is the second most recent and so on.

Initially, Polycarp's recent chat list pp looks like 1, 2, \dots, n (in other words, it is an identity permutation).

After that he receives mm messages, the jj -th message comes from the friend aja_j . And that causes friend aja_j to move to the first position in a permutation, shifting everyone between the first position and the current position of aja_j by 11 . Note that if the friend aja_j is in the first position already then nothing happens.

For example, let the recent chat list be p=[4,1,5,3,2]p = [4, 1, 5, 3, 2] :

  • if he gets messaged by friend 33 , then pp becomes [3,4,1,5,2][3, 4, 1, 5, 2] ;
  • if he gets messaged by friend 44 , then pp doesn't change [4,1,5,3,2][4, 1, 5, 3, 2] ;
  • if he gets messaged by friend 22 , then pp becomes [2,4,1,5,3][2, 4, 1, 5, 3] .

For each friend consider all position he has been at in the beginning and after receiving each message. Polycarp wants to know what were the minimum and the maximum positions.

输入格式

The first line contains two integers nn and mm ( 1n,m31051 \le n, m \le 3 \cdot 10^5 ) — the number of Polycarp's friends and the number of received messages, respectively.

The second line contains mm integers a1,a2,,ama_1, a_2, \cdots, a_m ( 1ain1 \le a_i \le n ) — the descriptions of the received messages.

输出格式

Print nn pairs of integers. For each friend output the minimum and the maximum positions he has been in the beginning and after receiving each message.

5 4
3 5 1 4
1 3
2 5
1 4
1 5
1 5
4 3
1 2 4
1 3
1 2
3 4
1 4

提示

In the first example, Polycarp's recent chat list looks like this:

  • [1,2,3,4,5][1, 2, 3, 4, 5]
  • [3,1,2,4,5][3, 1, 2, 4, 5]
  • [5,3,1,2,4][5, 3, 1, 2, 4]
  • [1,5,3,2,4][1, 5, 3, 2, 4]
  • [4,1,5,3,2][4, 1, 5, 3, 2]

So, for example, the positions of the friend 22 are 2,3,4,4,52, 3, 4, 4, 5 , respectively. Out of these 22 is the minimum one and 55 is the maximum one. Thus, the answer for the friend 22 is a pair (2,5)(2, 5) .

In the second example, Polycarp's recent chat list looks like this:

  • [1,2,3,4][1, 2, 3, 4]
  • [1,2,3,4][1, 2, 3, 4]
  • [2,1,3,4][2, 1, 3, 4]
  • [4,2,1,3][4, 2, 1, 3]