QOJ.ac

QOJ

Time Limit: 6.0 s Memory Limit: 2048 MB Total points: 100 Difficulty: [show] Hackable ✓
Statistics

陈教授是一位著名的计算古文字学专家,多年来一直致力于研究“无冗余王朝”的手稿。那个时代的抄写员遵循一种奇特的审美原则:他们认为如果文本中包含“回声”,就会失去其精神力量。

在这种背景下,“易位回声”(anagrammatic echo)被定义为文本中任意两个不同的片段,它们在顺序上不一定完全相同,但包含完全相同的字符且数量也完全相同。对于表示为符号序列的文本,如果存在两个不同的起始位置 $x$ 和 $y$,使得从 $x$ 开始的长度为 $l$ 的子数组是从 $y$ 开始的长度为 $l$ 的子数组的一个排列,则存在回声。例如,考虑序列 $[1, 2, 1, 1, 3, 1, 2, 1]$。从第二个位置开始的长度为 $4$ 的片段 $[2, 1, 1, 3]$,与从第五个位置开始的长度为 $4$ 的片段 $[3, 1, 2, 1]$,构成了一个易位回声。

陈教授发掘了几个这样的卷轴,但许多符号随着时间的推移已经褪色,留下了空缺(用 $0$ 表示)。您的任务是使用允许的集合 $\{1, 2, \dots, k\}$ 中的符号填补这些空缺,从而使卷轴最终的“不和谐度”(Dissonance Score)最小。不和谐度定义为填补完整后的序列中,任意易位回声的最大长度 $l$。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$ ($1 \le T \le 10^4$),表示测试数据的组数。对于每组测试数据:

第一行包含两个整数 $n$ 和 $k$ ($2 \le n \le 2 \times 10^5$, $1 \le k \le n$)。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le k$)。

保证所有测试数据的 $n$ 之和不超过 $2 \times 10^5$。

输出格式

对于每组测试数据,输出 $n$ 个整数 $b_1, b_2, \dots, b_n$ ($1 \le b_i \le k$),表示恢复后的序列。序列 $b$ 必须在所有 $a_i \neq 0$ 的位置与 $a$ 保持一致,且必须达到尽可能小的不和谐度。

如果存在多种最优的恢复卷轴的方式,陈教授接受其中任意一种。

样例

输入样例 1

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

输出样例 1

1 1 3 2 1 3 2 2
1 3 2
2 1 1 3 5 6 4 4 7
1 2 3 4 5 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.