CF1799A.Recent Actions

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

On Codeforces the "Recent Actions" field shows the last nn posts with recent actions.

Initially, there are posts 1,2,…,n1, 2, \ldots, n in the field (this is in order from top to down). Also there are infinitely many posts not in the field, numbered with integers n+1,n+2,…n + 1, n + 2, \ldots.

When recent action happens in the post pp:

  • If it is in the "Recent Actions" field, it moves from its position to the top position.
  • Otherwise, it is added to the top position, and the post on the down position is removed from the "Recent Actions" field.

You know, that the next mm recent actions will happen in the posts p1,p2,…,pmp_1, p_2, \ldots, p_m (n+1≤pi≤n+mn + 1 \leq p_i \leq n + m) in the moments of time 1,2,…,m1, 2, \ldots, m. Note, that recent actions only happen with posts with numbers ≥n+1\geq n + 1.

For each post ii (1≤i≤n1 \leq i \leq n), find the first time it will be removed from the "Recent Actions" field or say, that it won't be removed.

Codeforces 的“最近动态”栏显示最近的 nn 条动态帖子。

初始时,该栏中自上而下依次为帖子 1,2,…,n1, 2, \ldots, n。此外,还有无限多个未在该栏中显示的帖子,编号为 n+1,n+2,…n + 1, n + 2, \ldots。

当帖子 pp 发生一次最新动态时:

  • 若该帖子已在“最近动态”栏中,则它将从其当前位置移至最顶端;
  • 否则,该帖子被添加至最顶端,同时原位于最底端的帖子将从“最近动态”栏中移除。

已知接下来的 mm 次最新动态将依次发生在帖子 p1,p2,…,pmp_1, p_2, \ldots, p_m(其中 n+1≤pi≤n+mn + 1 \leq p_i \leq n + m)上,对应的时间点分别为 1,2,…,m1, 2, \ldots, m。注意:所有这些最新动态仅涉及编号 ≥n+1\geq n + 1 的帖子。

对每个帖子 ii(1≤i≤n1 \leq i \leq n),请找出其首次从“最近动态”栏中被移除的时间点;若其永远不会被移除,则说明这一点。

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. Descriptions of test cases follow.

The first line of each test case contains two integers nn, mm (1≤n,m≤5⋅1041 \leq n, m \leq 5 \cdot 10^4) — the size of the "Recent Actions" field and the number of actions.

The next line contains mm integers p1,p2,…,pmp_1, p_2, \ldots, p_m (n+1≤pi≤n+mn + 1 \leq p_i \leq n + m).

It is guaranteed, that the sum of nn and the sum of mm for all test cases does not exceed 5⋅1045 \cdot 10^4.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn、mm(1≤n,m≤5⋅1041 \leq n, m \leq 5 \cdot 10^4),分别表示“最近操作”区域的大小以及操作总数。

接下来一行包含 mm 个整数 p1,p2,…,pmp_1, p_2, \ldots, p_m(n+1≤pi≤n+mn + 1 \leq p_i \leq n + m)。

保证所有测试用例的 nn 之和与 mm 之和均不超过 5⋅1045 \cdot 10^4。

输出格式

For each test case print nn integers t1,t2,…,tnt_1, t_2, \ldots, t_n, where ti=−1t_i=-1 if the post ii won't be removed or tit_i equals to the first moment of time the post ii will be removed (1≤ti≤m1 \leq t_i \leq m).

对每个测试用例,输出 nn 个整数 t1,t2,…,tnt_1, t_2, \ldots, t_n,其中若第 ii 篇帖子不会被删除,则 ti=−1t_i = -1;否则 tit_i 等于第 ii 篇帖子首次被删除的时刻(1≤ti≤m1 \leq t_i \leq m)。

输入输出样例

  • 输入#1

    10
    1 1
    2
    3 2
    5 4
    4 5
    5 9 9 5 7
    5 5
    6 7 8 9 10
    3 4
    4 4 4 4
    4 4
    5 5 6 6
    3 5
    4 5 5 5 4
    4 20
    5 5 24 24 24 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20
    5 7
    7 8 7 11 7 12 10
    6 7
    8 11 7 8 8 8 12

    输出#1

    1 
    -1 2 1 
    -1 5 2 1 
    5 4 3 2 1 
    -1 -1 1 
    -1 -1 3 1 
    -1 2 1 
    8 7 3 1 
    7 6 4 2 1 
    -1 -1 7 3 2 1

说明/提示

In the first test case, the only post 11 will be removed at the moment 11 and replaced by the post 22.

In the second test case the "Recent Actions" field will be (given an order from top to down):

  1. Before moment 11: [1,2,3][1, 2, 3], after moment 11: [5,1,2][5, 1, 2]. Post number 33 was removed.
  2. Before moment 22: [5,1,2][5, 1, 2], after moment 22: [4,5,1][4, 5, 1]. Post number 22 was removed.

Post number 11 won't be removed.

In the third test case the "Recent Actions" field will be (given an order from top to down):

  1. Before moment 11: [1,2,3,4][1, 2, 3, 4], after moment 11: [5,1,2,3][5, 1, 2, 3]. Post number 44 was removed.
  2. Before moment 22: [5,1,2,3][5, 1, 2, 3], after moment 22: [9,5,1,2][9, 5, 1, 2]. Post number 33 was removed.
  3. Before moment 33: [9,5,1,2][9, 5, 1, 2], after moment 33: [9,5,1,2][9, 5, 1, 2]. Nothing was changed.
  4. Before moment 44: [9,5,1,2][9, 5, 1, 2], after moment 44: [5,9,1,2][5, 9, 1, 2]. The order was changed.
  5. Before moment 55: [5,9,1,2][5, 9, 1, 2], after moment 55: [7,5,9,1][7, 5, 9, 1]. Post number 22 was removed.

Post number 11 won't be removed.

在第一个测试用例中,唯一的一篇帖子 11 将在时刻 11 被移除,并被帖子 22 替换。

在第二个测试用例中,“最近操作”字段将呈现如下(按从上到下的顺序):

  1. 时刻 11 前:[1,2,3][1, 2, 3],时刻 11 后:[5,1,2][5, 1, 2]。帖子编号 33 被移除。
  2. 时刻 22 前:[5,1,2][5, 1, 2],时刻 22 后:[4,5,1][4, 5, 1]。帖子编号 22 被移除。

帖子编号 11 不会被移除。

在第三个测试用例中,“最近操作”字段将呈现如下(按从上到下的顺序):

  1. 时刻 11 前:[1,2,3,4][1, 2, 3, 4],时刻 11 后:[5,1,2,3][5, 1, 2, 3]。帖子编号 44 被移除。
  2. 时刻 22 前:[5,1,2,3][5, 1, 2, 3],时刻 22 后:[9,5,1,2][9, 5, 1, 2]。帖子编号 33 被移除。
  3. 时刻 33 前:[9,5,1,2][9, 5, 1, 2],时刻 33 后:[9,5,1,2][9, 5, 1, 2]。未发生任何变化。
  4. 时刻 44 前:[9,5,1,2][9, 5, 1, 2],时刻 44 后:[5,9,1,2][5, 9, 1, 2]。顺序发生了变化。
  5. 时刻 55 前:[5,9,1,2][5, 9, 1, 2],时刻 55 后:[7,5,9,1][7, 5, 9, 1]。帖子编号 22 被移除。

帖子编号 11 不会被移除。

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

首页