#P15109. Adverse Present

Adverse Present

Problem Description

You are given a permutation of length nn, and an integer tp{0,1}tp\in\{0,1\}.

One operation is defined as follows:

Choose a subsequence, delete it from the original sequence, and append it to the end of the permutation in the original order.

Please output the minimum number of operations kk needed to sort this permutation in increasing order, and also construct a sequence of operations. In particular, if kn3×106k\cdot n\geq 3\times 10^6 or tp=0tp=0, you do not need to construct it (see the input and output formats).

Definition of a permutation: a permutation of length nn is a sequence consisting of positive integers from 11 to nn, where each number appears exactly once.

Definition of a subsequence: we say that sequence bb is a subsequence of sequence aa if and only if bb can be obtained by deleting some elements from aa.

Input Format

The first line contains two integers n,tpn, tp, representing the permutation length, and whether you need to construct a solution.

The second line contains nn numbers. The ii-th number is the ii-th element of the permutation aia_i. It is guaranteed that all these numbers are pairwise distinct.

Output Format

The first line contains one number kk, representing the minimum number of operations needed.

If kn3×106k\cdot n\geq 3\times 10^6 or tp=0tp=0, output -1 on the second line and exit.

Otherwise, output the next kk lines. In each line, the first number cc is the length of the subsequence chosen in this operation. Then output cc pairwise distinct numbers, indicating which indices (in the current sequence) are chosen to form the subsequence. The order of these indices can be arbitrary.

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

Hint

This problem uses bundled testdata.

Subtask 1(1pts):\texttt{Subtask 1(1pts)}: ai=ia_i=i.

Subtask 2(19pts):\texttt{Subtask 2(19pts):} ai=ni+1a_i=n-i+1.

Subtask 3(15pts):\texttt{Subtask 3(15pts):} n5n\le 5.

Subtask 4(20pts):\texttt{Subtask 4(20pts):} n2×103n\le 2\times 10^3.

Subtask 5(15pts):\texttt{Subtask 5(15pts):} tp=0tp=0.

Subtask 6(30pts):\texttt{Subtask 6(30pts):} no special constraints.

For all data, 1n1051\leq n \leq 10^5, and it is guaranteed that aa is a permutation.

Translated by ChatGPT 5