logo AlgoBeat OnlineJudge
登录 注册

#214206. [ZJCPC 2017] Heap Partition

内存限制:512 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

A sequence is called if there exists a binary tree with nodes such that every node is labelled with exactly one element from the sequence , and for every non-root node and its parent , and hold. Each element in sequence can be used to label a node in tree only once.

Chiaki has a sequence , she would like to decompose it into a minimum number of heapable subsequences.

Note that a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

输入格式

There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case:

The first line contain an integer () -- the length of the sequence.

The second line contains integers ().

It is guaranteed that the sum of all does not exceed .

输出格式

For each test case, output an integer denoting the minimum number of heapable subsequences in the first line. For the next lines, first output an integer , indicating the length of the subsequence. Then output integers in increasing order on the same line, where means the index of the -th element of the -th subsequence in the original sequence.

样例

样例输入 1

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

样例输出 1

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