CF1288E.Messenger Simulator

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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,…,n1, 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.

Polycarp 是一款非常流行即时通讯软件的常客,他一直在与朋友们聊天。他共有 nn 位朋友,编号从 11 到 nn。

回忆一下:一个大小为 nn 的排列(permutation)是指一个长度为 nn 的数组,其中 11 到 nn 的每个整数恰好出现一次。

因此,他最近的聊天列表可用一个大小为 nn 的排列 pp 表示:p1p_1 是 Polycarp 最近聊天的朋友,p2p_2 是第二近的,依此类推。

初始时,Polycarp 的最近聊天列表 pp 为 1,2,…,n1, 2, \dots, n(即单位排列,identity permutation)。

随后,他收到 mm 条消息,其中第 jj 条消息来自朋友 aja_j。这会导致朋友 aja_j 移动到排列的首位,而原来位于首位至 aja_j 当前位置之间的所有朋友均向后移动一位。注意:若朋友 aja_j 已处于首位,则列表不发生变化。

例如,设当前聊天列表为 p=[4,1,5,3,2]p = [4, 1, 5, 3, 2]:

  • 若他收到朋友 33 发来的消息,则 pp 变为 [3,4,1,5,2][3, 4, 1, 5, 2];
  • 若他收到朋友 44 发来的消息,则 pp 保持不变:[4,1,5,3,2][4, 1, 5, 3, 2];
  • 若他收到朋友 22 发来的消息,则 pp 变为 [2,4,1,5,3][2, 4, 1, 5, 3]。

对每位朋友,考虑其在初始状态以及每次收到消息后的所有位置。Polycarp 想知道每位朋友所处过的最小位置和最大位置。

输入格式

The first line contains two integers nn and mm (1≤n,m≤3⋅1051 \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, \dots, a_m (1≤ai≤n1 \le a_i \le n) — the descriptions of the received messages.

第一行包含两个整数 nn 和 mm(1≤n,m≤3⋅1051 \le n, m \le 3 \cdot 10^5)—— 分别表示 Polycarp 的朋友数量和收到的消息数量。

第二行包含 mm 个整数 a1,a2,…,ama_1, a_2, \dots, a_m(1≤ai≤n1 \le a_i \le n)—— 表示收到的每条消息的描述。

输出格式

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.

输出 nn 对整数。对于每位朋友,输出他在初始时以及每次收到消息后的最小和最大位置。

输入输出样例

  • 输入#1

    5 4
    3 5 1 4

    输出#1

    1 3
    2 5
    1 4
    1 5
    1 5
  • 输入#2

    4 3
    1 2 4

    输出#2

    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]

在第一个例子中,Polycarp 最近的聊天列表如下所示:

  • [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]

因此,例如,朋友 22 的位置依次为 2,3,4,4,52, 3, 4, 4, 5。其中最小值为 22,最大值为 55。故朋友 22 的答案为二元组 (2,5)(2, 5)。

在第二个例子中,Polycarp 最近的聊天列表如下所示:

  • [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]

输入解题思路,AI测评打分。不知道怎么写?

首页