Universal Cup Judging System

Universal Cup

Limite de temps : 6.0 s Limite de mémoire : 2048 MB Points totaux : 100 Difficulté: [afficher] Hackable ✓
Statistiques

計算古文書学の著名な専門家である陳教授は、長年にわたり「非冗長(Non-Redundant)」王朝の古文書を研究してきました。この時代の書記官たちは奇妙な美学教義に従っており、文書に「反響(echo)」が含まれるとその霊的な力が失われると信じていました。

この文脈において、アナグラム反響(anagrammatic echo)とは、順序は必ずしも同一ではないものの、まったく同じ種類の記号をまったく同じ個数だけ含む、文書内の異なる $2$ つの部分列として定義されます。記号の列として表される文書において、異なる $2$ つの開始位置 $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$ のことです。

入力

複数のテストケースが与えられます。入力の $1$ 行目には、テストケースの数を表す整数 $T$($1 \le T \le 10^4$)が与えられます。各テストケースについて:

$1$ 行目には $2$ つの整数 $n$ と $k$($2 \le n \le 2 \times 10^5$, $1 \le k \le n$)が与えられます。

$2$ 行目には $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.