Universal Cup Judging System

Universal Cup

Límite de tiempo: 1.0 s Límite de memoria: 1024 MB Puntuación total: 100
Estadísticas

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.