QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#16526. Mex of Sequence

الإحصائيات

题目描述

给定一个长度为 $n$ 的序列 $a$ 和一个整数 $m$。

我们定义一次操作为,同时将序列 $a$ 中的每个元素 $a_i$ 替换为序列 $a$ 中除 $a_i$ 以外的所有元素的 $\operatorname{mex}$。

你需要求出进行 $m$ 次操作后的序列 $a$。

其中,一个序列的 $\operatorname{mex}$ 为该序列中未出现过的最小自然数,例如:

  • $\operatorname{mex}\{1,2,3\}=0$;
  • $\operatorname{mex}\{0\}=1$;
  • $\operatorname{mex}\{1,0,2,4\}=3$;
  • $\operatorname{mex}\{2,1,3,0,2\}=4$。

特别地,当序列为空时,该序列的 $\operatorname{mex}$ 为 $0$。

输入格式

本题有多组测试数据。

第一行输入一个整数 $T$,表示测试数据组数。

接下来依次输入每组测试数据。对于每组测试数据:

  • 第一行输入两个整数 $n,m$。
  • 第二行输入 $n$ 个整数,表示给定的序列 $a$。

输出格式

对于每组测试数据,输出一行,包含用空格分隔的 $n$ 个整数,表示进行 $m$ 次操作后的序列 $a$。

样例 1 输入

3
4 1
1 0 1 2
4 5
9 9 6 1
3 5
1 3 0

样例 1 输出

3 0 3 2
0 0 0 0
1 2 0

样例 1 解释

对于第 $1$ 组数据,因为 $\operatorname{mex}\{0,1,2\}=3$,$\operatorname{mex}\{1,1,2\}=0$,$\operatorname{mex}\{1,0,2\}=3$,$\operatorname{mex}\{1,0,1\}=2$,所以进行 $1$ 次操作后的序列 $a$ 为 $\{3,0,3,2\}$。

数据范围

设 $\sum n$ 表示单个测试点中 $n$ 的和。

对于所有数据,$1 \le T \le 1000$,$1 \le n \le 10^6$,$1 \le m \le 10^9$,$0 \le a_i \le 10^9$,$\sum n \le 10^6$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.