QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#962. 感谢 MikeMirzayanov

Statistics

你拥有一副包含 $n$ 张牌的牌堆,牌上的数字从 $1$ 到 $n$(在牌堆中的顺序不一定是有序的)。你需要通过重复执行以下操作来将牌堆排序。

选择 $2 \le k \le n$,并将牌堆分成 $k$ 个非空的连续部分 $D_1, D_2, \dots, D_k$($D_1$ 包含牌堆的前 $|D_1|$ 张牌,$D_2$ 包含接下来的 $|D_2|$ 张牌,以此类推)。然后反转这些部分的顺序,将牌堆变为 $D_k, D_{k-1}, \dots, D_2, D_1$(即新牌堆的前 $|D_k|$ 张牌是 $D_k$,接下来的 $|D_{k-1}|$ 张牌是 $D_{k-1}$,以此类推)。每个部分 $D_i$ 内部的牌的顺序在操作中保持不变。

你需要通过最多 $120$ 次操作得到一个有序的牌堆(即第一张牌是 $1$,第二张牌是 $2$,以此类推)。在题目给定的限制下,可以证明总是可以通过最多 $120$ 次操作将牌堆排序。

操作示例:以下是三种有效操作的示例(针对不同大小的牌堆)。

  • 如果牌堆是 $[3\ 6\ 2\ 1\ 4\ 5\ 7]$($3$ 是第一张牌,$7$ 是最后一张牌),我们可以执行 $k=4$ 的操作,其中 $D_1=[3\ 6]$,$D_2=[2\ 1\ 4]$,$D_3=[5]$,$D_4=[7]$。执行后,牌堆变为 $[7\ 5\ 2\ 1\ 4\ 3\ 6]$。
  • 如果牌堆是 $[3\ 1\ 2]$,我们可以执行 $k=3$ 的操作,其中 $D_1=[3]$,$D_2=[1]$,$D_3=[2]$。执行后,牌堆变为 $[2\ 1\ 3]$。
  • 如果牌堆是 $[5\ 1\ 2\ 4\ 3\ 6]$,我们可以执行 $k=2$ 的操作,其中 $D_1=[5\ 1]$,$D_2=[2\ 4\ 3\ 6]$。执行后,牌堆变为 $[2\ 4\ 3\ 6\ 5\ 1]$。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 20\,000$),表示牌堆中牌的数量。 第二行包含 $n$ 个整数 $c_1, c_2, \dots, c_n$,表示牌堆中的牌。第一张牌是 $c_1$,第二张牌是 $c_2$,以此类推。 保证对于所有的 $i = 1, \dots, n$,恰好存在一个 $j \in \{1, \dots, n\}$ 使得 $c_j = i$。

输出格式

第一行输出你执行的操作次数 $q$(必须满足 $0 \le q \le 120$)。 然后输出 $q$ 行,每行描述一次操作。 描述一次操作时,在一行内输出你将牌堆分成的部分数量 $k$,随后输出这 $k$ 个部分的长度:$|D_1|, |D_2|, \dots, |D_k|$。 必须满足 $2 \le k \le n$,且对于所有 $i = 1, \dots, k$ 都有 $|D_i| \ge 1$,以及 $|D_1| + |D_2| + \dots + |D_k| = n$。 可以证明在题目限制下,总是可以通过最多 $120$ 次操作将牌堆排序。如果存在多种排序方法,你可以输出其中任意一种。注意,你不需要最小化 $q$。

样例

样例输入 1

4
3 1 2 4

样例输出 1

2
3 1 2 1
2 1 3

样例输入 2

6
6 5 4 3 2 1

样例输出 2

1
6 1 1 1 1 1 1

样例输入 3

1
1

样例输出 3

0

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#613Editorial Open集训队作业 解题报告 by 王一策Qingyu2026-01-02 23:10:06 Download
#592Editorial Open集训队作业 解题报告 by 孙梓航Qingyu2026-01-02 22:41:14 Download
#322EditorialOpen题解jiangly2025-12-14 07:04:55View

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.