#6317. [ZJCPC 2017] Heap Partition

    ID: 6317 传统题 3000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P14105贪心2017浙江Special Judge省赛/邀请赛STL

[ZJCPC 2017] Heap Partition

[ZJCPC 2017] Heap Partition

题目描述

A sequence $S=\{s_1,s_2,\dots,s_n\}$ is called $\textit{heapable}$ if there exists a binary tree $T$ with $n$ nodes such that every node is labelled with exactly one element from the sequence $S$, and for every non-root node $s_i$ and its parent $s_j$, $s_j \le s_i$ and $j

Chiaki has a sequence a1,a2,…,ana_1,a_2,\dots,a_n, 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 $T$, indicating the number of test cases. For each test case:

The first line contain an integer nn (1≤n≤1051 \le n \le 10^5) -- the length of the sequence.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n).

It is guaranteed that the sum of all nn does not exceed 2×1062 \times 10^6.

输出格式

For each test case, output an integer $m$ denoting the minimum number of heapable subsequences in the first line. For the next $m$ lines, first output an integer $C_i$, indicating the length of the subsequence. Then output $C_i$ integers $P_{i1}, P_{i2}, \dots, P_{iC{_i}}$ in increasing order on the same line, where $P_{ij}$ means the index of the $j$-th element of the $i$-th subsequence in the original sequence.
4
4
1 2 3 4
4
2 4 3 1
4
1 1 1 1
5
3 2 1 4 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

提示

(暂无提示) 标签: P14105|贪心|2017|浙江|Special Judge|省赛/邀请赛|STL

来源

P14105|[ZJCPC 2017] Heap Partition