#P8223. [WFOI - 02] I wanna moqueve(位移序列)

    ID: 9153 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>洛谷原创Special JudgeO2优化随机化构造洛谷月赛

[WFOI - 02] I wanna moqueve(位移序列)

Background

It's my fiesta.

Before one match, kid was defeated on the map of WFOIR1; after one match, kid got up from where he fell.

kid succeeded; he is no longer who he used to be.

Simplified statement: Link\texttt{Link}.

After finishing this problem, why not go solve this problem as well?

Problem Description

kid needs to sort a permutation of 1n1 \sim n on a strange computer, and the next save point will only appear later.

kid can choose a number xx. Then, in each subsequent operation, kid may cyclically shift a subarray of length xx to the left or to the right (the leftmost / rightmost element moves to the rightmost / leftmost position). The shift amount is 11.

If kid performs more than 23×n23 \times n operations, the permutation will explode and kid will fall again. Therefore, please tell kid a way to restore the sequence; leave the remaining operations to €€£!

Input Format

The input has 22 lines:

The first line contains an integer nn, representing the length of the sequence.

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

Output Format

The output has m+2m + 2 lines.

The first two lines each contain one number, which are xx and mm respectively. mm is the number of operations.

The next mm lines each contain two numbers: the first is the left endpoint of the shifted interval, and the second is the direction, where 00 means shifting left and 11 means shifting right.

This problem uses SPJ\text{SPJ}. You will get accepted as long as the cyclic shift operations are correct.

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

Hint

  • Explanation for Sample 11:

    Shift left on interval (2,3)(2,3), the sequence becomes 2,1,32,1,3.

    Shift left on interval (1,2)(1,2), the sequence becomes 1,2,31,2,3.

  • Explanation for Sample 22:

    Shift right on interval (3,5)(3,5), the sequence becomes 4,2,1,3,54,2,1,3,5.

    Shift right on interval (1,3)(1,3), the sequence becomes 1,4,2,3,51,4,2,3,5.

    Shift left on interval (2,4)(2,4), the sequence becomes 1,2,3,4,51,2,3,4,5.

This problem uses bundled Subtasks.

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