Universal Cup Judging System

Universal Cup

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$ 相同,且必須達到最小可能的不和諧分數。

若有多種最佳的卷軸復原方式,陳教授會接受其中任意一種。

範例

輸入

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 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.