QOJ.ac

QOJ

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

#20098. 順序を保つ

الإحصائيات

Gon は $1$ から $n$ まで(両端を含む)の整数の順列 $a=(a_1,a_2,\ldots,a_n)$ を持っており、これを昇順に並べ替えたいと思っています。しかし、ソートは簡単です。誰でも配列をソートできます!

そこで、Gon は次の操作だけを使ってソートすることにしました。

  • 2 つの添字 $\ell$ と $r$($1\le\ell\le r\le n$)を選びます。ただし、部分配列 $(a_\ell,a_{\ell+1},\ldots,a_r)$ は昇順または降順に整列している必要があります。

  • $\ell$ から $r$ までの部分配列を反転します。

例えば、順列 $a=(3,2,1)$ が与えられた場合、Gon は次のように 1 回の操作でソートできます。

  • $\ell=1,r=3$ を選びます。

  • 部分配列 $(a_1,a_2,a_3)$ を反転し、$a=(1,2,3)$ を得ます。

$a=(3,1,2)$ の場合、$1$ から $3$ までの部分配列が整列していないため、Gon は $\ell=1,r=3$ を選ぶことができないことに注意してください。

Gon の誕生日は 1 月 19 日なので、Gon は操作を最大 $191$ 回までにしたいと思っています。これは簡単ではありません。Gon を助けてください!

入力

入力の 1 行目には整数 $n$($1\le n\le100$)が与えられます。

入力の 2 行目には $n$ 個の整数 $a_1,a_2,\ldots,a_n$ が与えられます。$a$ は $1$ から $n$ まで(両端を含む)の整数の順列であることが保証されます。

出力

1 行目に、使用する操作の回数を表す数 $k$($0\le k\le191$)を出力してください。

続く $k$ 行の各行に、操作を表す 2 つの整数 $\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.