#P9291. [ROI 2018] Quick sort
[ROI 2018] Quick sort
Background
Translated from ROI 2018 Day2 T2. Быстрая сортировка (Quick sort).
Problem Description
You are given a permutation of length .
Define an operation as follows: rearrange the segment into .
For example: $[2, 4, 1, 5, 3, 6, 7, 8]\xrightarrow{S(2,6)} [2, 1, 3, 4, 5, 6, 7, 8]$, where the subarray is rearranged into .
Given a permutation, find how many operations are needed to make it increasing, and output any valid sequence of operations. You do need to minimize the number of operations, but you must ensure the number of operations is .
Input Format
The first line contains an integer .
The second line contains integers, representing the permutation .
Output Format
The first line contains an integer , the number of operations you perform. It must satisfy .
In the next lines, describe your operations in order. For each step, output two integers , , meaning you apply the operation once to the segment . It must satisfy .
Note that you do not need to minimize . You only need to guarantee . It is guaranteed that such a exists.
5
3 1 4 2 5
1
1 5
8
2 4 1 5 3 6 7 8
2
2 6
1 2
2
2 1
3
1 1
2 2
1 2
Hint
Let be the minimum number of operations.
For all testdata, , , , and all are distinct.
| Subtask ID | Special property | |
|---|---|---|
| None | ||
Translated by ChatGPT 5