问题 G: Stone Merging

内存限制:1024 MB 时间限制:1 S
题面:Markdown 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Randias has $n$ stones, the $i$\-th stone has number $a_{i}$ written on it. Initially, $n$ stones are piled up separately (which means they form $n$ piles, and each pile contains one stone). Randias has $k-1$ machines, numbered from $2$ to $k$. The machine numbered $i$ can merge exactly $i$ piles into one single pile. Unfortunately, if the piles put into machine $i$ contain a stone with number $i$, then the machine will act differently. The machine will output two piles; the first one contains all stones with number $i$, and the second one contains all remaining stones (the second one may be empty). After that, machine $i$ will be broken, which means that it can not be used again. Randias can use any machine any number of times before it is broken. He wants to merge all the stones into one pile. Please help him to determine how to merge the stones, or determine if it is impossible.

输入格式

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 1.2 \cdot 10^4$), denoting the number of test cases. For each test case, the first line contains two integers $n,k$ ($2\le k \le n \le 10^5$), denoting the number of stones and the limit of machines. The second line contains $n$ integers $a_{1},a_{2} \dots a_{n}$ ($1\le a_{i} \le n$), denoting the number written on each stone. It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

输出格式

For each test case, if it is impossible to merge all stones in one pile, output ''-1''(without quotes). Otherwise, on the first line, output the number of operations $L$ ($0\le L \le n$). We assign a unique ID to each pile. The IDs of the initial piles are $1,2, \dots n$. The two piles possibly created by the $i$\-th operation have the ID $n + 2\cdot i - 1$ and $n + 2\cdot i$. Let $m_{i}$ be the number of piles merged in the $i$\-th operation. The pile with ID $n+2\cdot i - 1$ contains all stones with number $m_{i}$ written on it, and the pile with ID $n + 2\cdot i$ contains the remaining stones. Note that one of the piles may be empty, but we still assign an ID for it. Also, if the pile with ID $n + 2\cdot i - 1$ is not empty, which means machine $m$ will be broken after this operation, and you can never use it again. For each operation, output it in a single line. First output $m_{i}$ ($2\le m_{i} \le k$), the number of piles that need to be merged. Then followed by $m_{i}$ distinct integers $c_{1},c_{2} \dots c_{m_{i}}$, each of them denoting a **non-empty** pile. This represents merging piles with ID $c_{1},c_{2} \dots c_{m_{i}}$, and creates two new piles with ID $n+2\cdot i - 1$, $n+2\cdot i$. After this operation, piles with ID $c_{1},c_{2} \dots c_{m_{i}}$ become empty. You should make sure that the machine $m_i$ is not broken before this operation. After all the operations, you should make sure there is only one non-empty pile, which contains all $n$ stones. In a single test case, you should make sure that $\sum{ m_{i}} \le 3 \cdot n$.

输入样例 复制

5
2 2
1 2
3 3
2 2 1
4 3
2 2 2 4
6 4
2 2 3 3 3 5
2 2
2 2

输出样例 复制

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