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.