Universal Cup Judging System

Universal Cup

Limite de temps : 2.0 s Limite de mémoire : 512 MB Points totaux : 100
Statistiques

Du får en heltalsmatris $a$ av storlek $n \times 2$. Elementen i den första kolumnen i matrisen $a$ bildar en permutation av värdena $n + 1, n + 2, \dots, 2n$, och elementen i den andra kolumnen bildar en permutation av värdena $1, 2, \dots, n$.

Du kan göra valfritt antal drag. I ett drag kan du göra följande:

  • Välj ett godtyckligt positivt heltal $k$.
  • Välj en sekvens av $k$ distinkta tal $(b_1, b_2, \dots, b_k)$, sådana att $1 \le b_i \le 2n$ för alla $1 \le i \le k$.
  • Skifta alla valda tal i matrisen cykliskt (talet $b_1$ flyttas till positionen för $b_2$, talet $b_2$ flyttas till positionen för $b_3$, ..., talet $b_k$ flyttas till positionen för $b_1$).
  • Betala $k$ mynt.

Vilket är det minsta antalet mynt du måste betala för att det vänstra elementet ska bli mindre än det högra elementet på varje rad? Observera att det inte krävs att antalet drag minimeras.

Indata

Den första raden innehåller ett heltal $t$ – antalet testfall. Den första raden i varje testfall innehåller ett heltal $n$ – antalet rader i matrisen $a$. De följande $n$ raderna i varje testfall innehåller två heltal $a_{i,1}$ och $a_{i,2}$ – matrisens element.

Utdata

För varje testfall, skriv ut svaret i följande format. På den första raden, skriv ut det minsta antalet mynt. På den andra raden, skriv ut ett heltal $m$ – antalet drag. På de följande $m$ raderna, skriv ut dragen i formatet $k \ b_1 \ b_2 \ b_3 \dots b_k$.

Begränsningar

$1 \le t \le 10^6$, $1 \le n \le 10^6$, summan av $n$ över alla testfall överstiger inte $10^6$.

Exempel

Indata 1

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

Utdata 1

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

Anmärkning

I det första exemplet ges matrisen $a = \begin{pmatrix} 5 & 1 \\ 6 & 2 \\ 7 & 3 \\ 8 & 4 \end{pmatrix}$.

En av de optimala strategierna för denna matris är att göra ett drag med $k = 4, b = (1, 7, 2, 8)$. Under detta drag: flyttas $1$ till positionen för $7$, flyttas $7$ till positionen för $2$, flyttas $2$ till positionen för $8$, flyttas $8$ till positionen för $1$.

Efter draget blir matrisen $a$ $\begin{pmatrix} 5 & 8 \\ 6 & 7 \\ 1 & 3 \\ 2 & 4 \end{pmatrix}$. Nu gäller att det vänstra elementet på varje rad är mindre än det högra elementet.

Det totala antalet betalade mynt är fyra.

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.