#P7999. [WFOI - 01] 翻转序列(requese)

    ID: 9085 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>洛谷原创Special JudgeO2优化其它技巧构造洛谷月赛

[WFOI - 01] 翻转序列(requese)

Background

Simplified statement: Link\texttt{Link}

Why don’t you go solve this problem after finishing this one?

Problem Description

You need to sort a permutation of 1n1\sim n on a strange computer.

You may choose a number xx. Then each time, you may reverse a segment of length x+1x+1 or a segment of length x1x-1.

Please restore the sequence to 1n1\sim n within 20×n20\times n operations.

(Setter’s note: The current best can be under 15000 operations. Please try to optimize your algorithm.)

Input Format

The input consists of 22 lines.

The first line contains an integer nn.

The second line contains nn integers, representing the sequence aa.

Output Format

The output consists of m+2m + 2 lines.

The first two lines each contain 11 integer, which are x,mx,m respectively. Here, mm is the number of operations.

The next mm lines each contain two integers, representing the left and right endpoints of the reversed interval.

This problem uses SPJ\text{SPJ}, and you will be judged as long as the reverse operations are correct.

2
2 1
1
1
1 2
5
5 2 3 4 1
4
2
1 5
2 4

Hint

  • Sample 11 explanation:

    Reverse (1,2)(1,2), and the sequence becomes 1,21,2.

  • Sample 22 explanation:

    Reverse (1,5)(1,5), and the sequence becomes 1,4,3,2,51,4,3,2,5.

    Reverse (2,4)(2,4), and the sequence becomes 1,2,3,4,51,2,3,4,5.

This problem uses bundled Subtask tests.

Subtask ID Constraints and Notes
Subtask #0 (1 pts\texttt{1 pts}) n=1n=1
Subtask #1 (2 pts\texttt{2 pts}) n=2n=2
Subtask #2 (3 pts\texttt{3 pts}) n=3n=3
Subtask #3 (4 pts\texttt{4 pts}) n=4n=4
Subtask #4 (20 pts\texttt{20 pts}) 1n501\le n\le 50
Subtask #5 (20 pts\texttt{20 pts}) 1n1001\le n\le 100
Subtask #6 (50 pts\texttt{50 pts}) 1n1031\le n\le 10^3

For 100%100\% of the testdata, 1n,ai1031\le n,a_i\le 10^3, and the data guarantees that aa is a permutation of 1n1\sim n.

Translated by ChatGPT 5