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]$。由第 $2$ 個位置開始、長度為 $4$ 嘅片段 $[2, 1, 1, 3]$,同埋由第 $5$ 個位置開始、長度為 $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.