Universal Cup Judging System

Universal Cup

حد الوقت: 2.0 s حد الذاكرة: 512 MB مجموع النقاط: 100
الإحصائيات

給定一個大小為 $n \times 2$ 的整數矩陣 $a$。矩陣 $a$ 第一行的元素是 $n + 1, n + 2, \dots, 2n$ 的一個排列,第二行的元素是 $1, 2, \dots, n$ 的一個排列。

你可以進行任意次數的操作。在一次操作中,你可以執行以下步驟:

  • 選擇任意正整數 $k$。
  • 選擇一個包含 $k$ 個相異數字的序列 $(b_1, b_2, \dots, b_k)$,使得對於所有 $1 \le i \le k$,滿足 $1 \le b_i \le 2n$。
  • 將矩陣中所有選定的數字進行循環移位(數字 $b_1$ 移動到 $b_2$ 的位置,數字 $b_2$ 移動到 $b_3$ 的位置,……,數字 $b_k$ 移動到 $b_1$ 的位置)。
  • 支付 $k$ 枚硬幣。

為了使每一列左側的元素都小於右側的元素,你需要支付的最少硬幣數量是多少?注意,不需要最小化操作次數。

輸入格式

第一行包含一個整數 $t$ —— 測試資料的數量。 每組測試資料的第一行包含一個整數 $n$ —— 矩陣 $a$ 的列數。 每組測試資料接下來的 $n$ 行包含兩個整數 $a_{i,1}$ 和 $a_{i,2}$ —— 矩陣的元素。

輸出格式

對於每組測試資料,按以下格式輸出答案: 第一行輸出最少支付的硬幣數量。 第二行輸出一個整數 $m$ —— 操作次數。 接下來的 $m$ 行,按格式 $k \ b_1 \ b_2 \ b_3 \dots b_k$ 輸出每次操作。

資料範圍

$1 \le t \le 10^6$, $1 \le n \le 10^6$, 所有測試資料中 $n$ 的總和不超過 $10^6$。

範例

輸入 1

2
4
5 1
6 2
7 3
8 4
3
4 2
5 1
6 3

輸出 1

4
1
4 1 7 2 8
4
2
2 1 6
2 4 2

說明

在第一個範例中,給定的矩陣為 $a = \begin{pmatrix} 5 & 1 \\ 6 & 2 \\ 7 & 3 \\ 8 & 4 \end{pmatrix}$。

該矩陣的一種最佳策略是進行一次操作,選擇 $k = 4, b = (1, 7, 2, 8)$。 在此次操作中: $1$ 移動到 $7$ 的位置, $7$ 移動到 $2$ 的位置, $2$ 移動到 $8$ 的位置, $8$ 移動到 $1$ 的位置。

操作後,矩陣 $a$ 變為 $\begin{pmatrix} 5 & 8 \\ 6 & 7 \\ 1 & 3 \\ 2 & 4 \end{pmatrix}$。現在,每一列中左側元素都小於右側元素。

支付的硬幣總數為四枚。

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.