QOJ.ac

QOJ

حد الوقت: 3.0 s حد الذاكرة: 256 MB مجموع النقاط: 100 قابلة للهجوم ✓

#6788. 堆分区

الإحصائيات

如果一个序列 $S = \{s_1, s_2, \dots, s_n\}$ 存在一棵包含 $n$ 个节点的二叉树 $T$,使得每个节点恰好被序列 $S$ 中的一个元素标记,且对于每个非根节点 $s_i$ 及其父节点 $s_j$,满足 $s_j \le s_i$ 且 $j < i$,则称该序列为“可堆叠的”(heapable)。序列 $S$ 中的每个元素在树 $T$ 中只能使用一次。

Chiaki 有一个序列 $a_1, a_2, \dots, a_n$,她想将其分解为最少数量的可堆叠子序列。

注意:子序列是指通过删除原序列中某些元素且不改变剩余元素顺序而得到的序列。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含一个整数 $n$ ($1 \le n \le 10^5$),表示序列的长度。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$)。

保证所有 $n$ 的总和不超过 $2 \times 10^6$。

输出格式

对于每组测试数据,第一行输出一个整数 $m$,表示最少需要的可堆叠子序列数量。接下来的 $m$ 行,每行首先输出一个整数 $C_i$,表示该子序列的长度。随后在同一行按升序输出 $C_i$ 个整数 $P_{i1}, P_{i2}, \dots, P_{iC_i}$,其中 $P_{ij}$ 表示第 $i$ 个子序列中第 $j$ 个元素在原序列中的下标。

样例

输入 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

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.