QOJ.ac

QOJ

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

#20098. 保持有序

الإحصائيات

Gon 有一个由 $1$ 到 $n$(含端点)的整数构成的排列 $a=(a_1,a_2,\ldots,a_n)$,想将它按递增顺序排序。然而,排序很简单——任何人都能将数组排序!

因此,Gon 决定只使用以下操作进行排序:

  • 选择两个下标 $\ell$ 和 $r$($1\le\ell\le r\le n$),使子数组 $(a_\ell,a_{\ell+1},\ldots,a_r)$ 已按递增或递减顺序排列。

  • 将从 $\ell$ 到 $r$ 的子数组反转。

例如,给定排列 $a=(3,2,1)$,Gon 可以通过以下一次操作将它排序:

  • 选择 $\ell=1,r=3$。

  • 反转子数组 $(a_1,a_2,a_3)$,得到 $a=(1,2,3)$。

注意,如果 $a=(3,1,2)$,Gon 不能选择 $\ell=1,r=3$,因为从 $1$ 到 $3$ 的子数组并非有序。

由于 Gon 的生日是 1 月 19 日,Gon 希望至多使用 $191$ 次操作。这就不那么简单了。请帮助 Gon!

输入格式

输入的第一行包含一个整数 $n$($1\le n\le100$)。

输入的第二行包含 $n$ 个整数 $a_1,a_2,\ldots,a_n$。保证 $a$ 是由 $1$ 到 $n$(含端点)的整数构成的排列。

输出格式

在第一行输出一个数 $k$($0\le k\le191$)——你想使用的操作次数。

在接下来的 $k$ 行中,每行输出两个整数 $\ell$ 和 $r$($1\le\ell\le r\le n$),描述操作。执行该操作前,$\ell$ 到 $r$ 之间的子数组必须有序。

经过 $k$ 次操作后,排列 $a$ 必须按递增顺序排列。换句话说,对每个合法下标 $i$,都有 $a_i=i$。注意,你不需要最小化操作次数。

保证存在解。如果有多个解,可以输出任意一个。

样例

输入格式 1

3
3 1 2

输出格式 1

7
1 1
2 2
3 3
1 2
2 3
1 3
1 3

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.