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

说明 1

在第一个样例中,给定的矩阵 $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.