QOJ.ac

QOJ

Süre Sınırı: 1 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓

#20098. 정렬된 상태로 유지하기

İstatistikler

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)$라면 $1$부터 $3$까지의 부분 배열이 정렬되어 있지 않으므로 Gon은 $\ell=1,r=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.