#P8381. [PFOI Round1] Two Subsegments
[PFOI Round1] Two Subsegments
Background
A well-known Luogu internet celebrity, comrade €€£, leader of the €€£ official team, passed away on April 17 after unsuccessful emergency treatment in the hospital.
€€£ was a well-known person on Luogu. He joined Luogu in 2021 and founded the €€£ official team in the same year. During his time in charge, he worked diligently, made jokes seriously, worked hard on creating problems, and contributed to making the “joke revolution” more standardized, modernized, and formalized.
Regarding the retirement of €€£, Uvocde felt deeply sad. At this time, he remembered €€£ ’s deep love for construction problems, so he made this problem to commemorate €€£.
Problem Description
There are queries. Each query gives a sequence of length , and it is guaranteed that is a permutation of .
You may choose a number . Then, each time you may move a subsegment of length or a subsegment of length forward or backward by positions within the original sequence, and move the part passed over into the vacated space.
Please sort in nondecreasing order within operations.
Input Format
The first line contains a positive integer .
Then there are lines. Every two lines represent one query.
For each query, the format is: first a line with a positive integer , then a line with positive integers representing .
Output Format
Output a total of groups.
If a query has no solution, output only .
If it has a solution, output lines in total:
The first two lines each contain one number, respectively , where is the number of operations, and is as described above.
Then output lines, each with three numbers. The first number indicates the direction ( means left, means right). The next two numbers represent the left and right endpoints of the shifted segment.
Your solution must satisfy:
- , .
- For each operation:
- .
- or .
- When shifting right, ; when shifting left, .
This problem uses . You will get points as long as your operations are correct or you correctly determine that there is no solution.
2
7
2 1 4 7 6 5 3
2
2 1
3
4
1 1 4
1 2 3
1 1 2
0 5 6
-1
Hint
[Sample Explanation]
For the sample :
Let be , and perform operations in total:
- 2 1 4 7 6 5 3, shift right.
- 6 5 3 2 1 4 7, shift right.
- 6 2 1 4 5 3 7, shift right.
- 1 4 5 6 2 3 7, shift left.
- 1 2 3 4 5 6 7, sorting finished.
[Constraints]
For of the testdata, . It is guaranteed that the permutation is uniformly random among all permutations.
| Number of tests | Constraints | Score | |
|---|---|---|---|
Translated by ChatGPT 5