#P8381. [PFOI Round1] Two Subsegments

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

[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 TT queries. Each query gives a sequence aa of length nn, and it is guaranteed that aa is a permutation of 1n1\sim n.

You may choose a number xx. Then, each time you may move a subsegment of length x+1x+1 or a subsegment of length x1x-1 forward or backward by xx positions within the original sequence, and move the part passed over into the vacated space.

Please sort aa in nondecreasing order within 80×n80\times n operations.

Input Format

The first line contains a positive integer TT.

Then there are 2×T2 \times T lines. Every two lines represent one query.

For each query, the format is: first a line with a positive integer nn, then a line with nn positive integers representing a1,,ana_1,\ldots,a_n.

Output Format

Output a total of TT groups.

If a query has no solution, output only 1-1.

If it has a solution, output m+2m+2 lines in total:

The first two lines each contain one number, respectively x,mx,m, where mm is the number of operations, and xx is as described above.

Then output mm lines, each with three numbers. The first number indicates the direction (00 means left, 11 means right). The next two numbers l,rl,r represent the left and right endpoints of the shifted segment.

Your solution must satisfy:

  • 2xn2\leq x\leq n, 0m80n0\leq m\leq 80n.
  • For each operation:
    • 1lrn1\leq l\leq r\leq n.
    • rl+1=x1r-l+1=x-1 or rl+1=x+1r-l+1=x+1.
    • When shifting right, rnxr\leq n-x; when shifting left, lx+1l\geq x+1.

This problem uses SPJ\text{SPJ}. 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 2 1 4 7 6 5 32\ 1\ 4\ 7\ 6\ 5\ 3:

Let xx be 33, and perform 44 operations in total:

  1. 2 1 4 7 6 5 3, shift right.
  2. 6 5 3 2 1 4 7, shift right.
  3. 6 2 1 4 5 3 7, shift right.
  4. 1 4 5 6 2 3 7, shift left.
  5. 1 2 3 4 5 6 7, sorting finished.

[Constraints]

For 100%100\% of the testdata, 1T104, 2n104, n1041\le T\le10^4,\ 2\le n\le 10^4,\ \sum n\le10^4. It is guaranteed that the permutation is uniformly random among all permutations.

Subtasks\text{Subtasks} Number of tests Constraints Score
Subtask0\text{Subtask0} 11 n5n\leq 5 2pts\text{2pts}
Subtask1\text{Subtask1} 77 n50n\leq 50 7pts\text{7pts}
Subtask2\text{Subtask2} 99 n103n\leq 10^3 27pts\text{27pts}
Subtask3\text{Subtask3} 1414 n5×103n\leq 5\times 10^3
Subtask4\text{Subtask4} 99 n104n\leq 10^4 37pts\text{37pts}

Translated by ChatGPT 5