#P10032. 「Cfz Round 3」Mex of Sequence

    ID: 11215 远端评测题 500ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>模拟洛谷原创O2优化排序其它技巧洛谷月赛Ad-hoc

「Cfz Round 3」Mex of Sequence

Problem Description

Please note the special time limit of this problem.

Given a sequence aa of length nn and an integer mm.

We define one operation as: simultaneously replace each element aia_i in sequence aa with the mex\operatorname{mex} of all elements in sequence aa except aia_i.

You need to output the sequence aa after performing mm operations.

Here, the mex\operatorname{mex} of a sequence is the smallest natural number that does not appear in the sequence. For example:

  • mex{1,2,3}=0\operatorname{mex}\{1,2,3\}=0.
  • mex{0}=1\operatorname{mex}\{0\}=1.
  • mex{1,0,2,4}=3\operatorname{mex}\{1,0,2,4\}=3.
  • mex{2,1,3,0,2}=4\operatorname{mex}\{2,1,3,0,2\}=4.

In particular, when the sequence is empty, its mex\operatorname{mex} is 00.

Input Format

This problem has multiple test cases.

The first line contains an integer TT, the number of test cases.

Then the test cases follow. For each test case:

  • The first line contains two integers n,mn,m.
  • The second line contains nn integers, representing the given sequence aa.

Output Format

For each test case, output one line containing nn integers separated by spaces, representing the sequence aa after performing mm operations.

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

Hint

"Sample Explanation #1"

For the first test case, since mex{0,1,2}=3\operatorname{mex}\{0,1,2\}=3, mex{1,1,2}=0\operatorname{mex}\{1,1,2\}=0, mex{1,0,2}=3\operatorname{mex}\{1,0,2\}=3, and mex{1,0,1}=2\operatorname{mex}\{1,0,1\}=2, the sequence aa after performing 11 operation is {3,0,3,2}\{3,0,3,2\}.

Constraints

Let n\sum n be the sum of nn within a single test point.

For all testdata, 1T10001 \le T \le 1000, 1n1061 \le n \le 10^6, 1m1091 \le m \le 10^9, 0ai1090 \le a_i \le 10^9, and n106\sum n \le 10^6.

You can get the score for this problem only if you pass all test points.

Translated by ChatGPT 5