欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1579B.Shifting Sort
Shifting Sort
The new generation external memory contains an array of integers .
This type of memory does not support changing the value of an arbitrary element. Instead, it allows you to cut out any segment of the given array, cyclically shift (rotate) it by any offset and insert it back into the same place.
Technically, each cyclic shift consists of two consecutive actions:
- You may select arbitrary indices and () as the boundaries of the segment.
- Then you replace the segment with it's cyclic shift to the left by an arbitrary offset . The concept of a cyclic shift can be also explained by following relations: the sequence is a cyclic shift of the sequence to the left by the offset and the sequence is a cyclic shift of the sequence to the left by the offset .
For example, if , then choosing , and yields a segment . This segment is then shifted by the offset to the left, and you get a segment which then takes the place of of the original elements of the segment. In the end you get .
Sort the given array using no more than cyclic shifts of any of its segments. Note that you don't need to minimize the number of cyclic shifts. Any method that requires or less cyclic shifts will be accepted.
Input
The first line contains an integer () — the number of test cases.
The next lines contain the descriptions of the test cases.
The first line of each test case description contains an integer () — the length of the array. The second line consists of space-separated elements of the array (). Elements of array may repeat and don't have to be unique.
Output
Print answers to all input test cases.
The first line of the answer of each test case should contain an integer () — the number of actions to sort the array. The next lines should contain descriptions of the actions formatted as " " (without quotes) where and () are the boundaries of the segment being shifted, while () is the offset value. Please remember that only the cyclic shifts to the left are considered so the chosen segment will be shifted by the offset to the to the left.
Note that you are not required to find the minimum number of cyclic shifts needed for sorting. Any sorting method where the number of shifts does not exceed will be accepted.
If the given array is already sorted, one of the possible answers is and an empty sequence of cyclic shifts.
If there are several possible answers, you may print any of them.
Note
Explanation of the fourth data set in the example:
- The segment is selected and is shifted to the left by : $[2, \color{blue}{5, 1, 4}, 3] \longrightarrow [2, \color{blue}{4, 5, 1}, 3]$
- The segment is then selected and is shifted to the left by : $[\color{blue}{2, 4, 5, 1, 3}] \longrightarrow [\color{blue}{1, 3, 2, 4, 5}]$
- After that the segment is selected and is shifted to the left by : $[\color{blue}{1, 3}, 2, 4, 5] \longrightarrow [\color{blue}{3, 1}, 2, 4, 5]$
- And in the end the segment is selected and is shifted to the left by : $[\color{blue}{3, 1, 2}, 4, 5] \longrightarrow [\color{blue}{1, 2, 3}, 4, 5]$
Samples
4
2
2 1
3
1 2 1
4
2 4 1 3
5
2 5 1 4 3
1
1 2 1
1
1 3 2
3
2 4 1
2 3 1
1 3 2
4
2 4 2
1 5 3
1 2 1
1 3 1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |