Universal Cup Judging System

Universal Cup

时间限制: 1.0 s 内存限制: 1024 MB 总分: 100
统计

Alice 同 Bob 有 $2n$ 張卡牌,每張卡牌上面寫住一個整數,使得 $1$ 到 $n$ 之間嘅每個整數都恰好喺兩張卡牌上面出現。最初,Alice 同 Bob 各自攞住 $n$ 張卡牌。

佢哋準備玩一個卡牌遊戲,由 Alice 先手。喺每個回合,當前玩家從手中攞出一張卡牌放喺牌堆頂部。如果此時牌堆入面有兩張數字相同嘅卡牌,當前玩家就會得到 $1$ 分,並將呢兩張相同嘅卡牌連同佢哋中間嘅所有卡牌一齊移走,放入棄牌堆。

畀定 Alice 嘅出牌順序,Bob 應該點樣安排自己嘅出牌順序,先可以令 Alice 嘅得分最小?

輸入格式

第一行包含一個整數 $T$($1 \le T \le 10^5$),表示測試數據組數。

對於每組測試數據,第一行包含一個整數 $n$($1 \le n \le 5 \times 10^5$)。

第二行包含 $n$ 個整數 $a_1, a_2, \dots, a_n$($1 \le a_i \le n$),按順序表示 Alice 打出嘅卡牌上面嘅數字。保證冇任何數字喺 $a_i$ 入面出現超過兩次。

保證所有測試數據中 $n$ 嘅總和唔超過 $5 \times 10^5$。

輸出格式

對於每組測試數據,輸出嘅第一行應包含一個整數,表示 Alice 可以獲得嘅最小得分。

第二行應包含 $n$ 個整數 $b_1, b_2, \dots, b_n$($1 \le b_i \le n$),按順序表示 Bob 嘅出牌,使得 $1$ 到 $n$ 嘅每個整數喺 $a_i$ 同 $b_i$ 合併後嘅序列入面都恰好出現兩次。

範例

輸入

3
3
1 2 3
5
3 1 4 1 5
5
1 4 5 1 4

輸出

0
1 2 3
0
2 3 2 4 5
1
3 2 2 3 5

提示

對於第三組測試數據,遊戲過程如下:

步驟 玩家 打出嘅牌 從底到頂嘅牌堆 Alice 嘅得分 Bob 嘅得分
$1$ Alice $1$ $[1]$ $0$ $0$
$2$ Bob $3$ $[1, 3]$ $0$ $0$
$3$ Alice $4$ $[1, 3, 4]$ $0$ $0$
$4$ Bob $2$ $[1, 3, 4, 2]$ $0$ $0$
$5$ Alice $5$ $[1, 3, 4, 2, 5]$ $0$ $0$
$6$ Bob $2$ $[1, 3, 4]$ $0$ $1$
$7$ Alice $1$ $[]$ $1$ $1$
$8$ Bob $3$ $[3]$ $1$ $1$
$9$ Alice $4$ $[3, 4]$ $1$ $1$
$10$ Bob $5$ $[3, 4, 5]$ $1$ $1$

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.