欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2001B.Generate Permutation
Generate Permutation
There is an integer sequence of length , where each element is initially .
Misuki has two typewriters where the first one writes letters from left to right, with a pointer initially pointing to , and another writes letters from right to left with a pointer initially pointing to .
Misuki would choose one of the typewriters and use it to perform the following operations until becomes a permutation of
- write number: write the minimum positive integer that isn't present in the array to the element , is the position where the pointer points at. Such operation can be performed only when .
- carriage return: return the pointer to its initial position (i.e. for the first typewriter, for the second)
- move pointer: move the pointer to the next position, let be the position the pointer points at before this operation, if Misuki is using the first typewriter, would happen, and otherwise. Such operation can be performed only if after the operation, holds.
Your task is to construct any permutation of length , such that the minimum number of carriage return operations needed to make is the same no matter which typewriter Misuki is using.
Input
Each test contains multiple test cases. The first line of input contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the length of the permutation.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a line of integers, representing the permutation of length such that the minimum number of carriage return operations needed to make is the same no matter which typewriter Misuki is using, or if it is impossible to do so.
If there are multiple valid permutations, you can output any of them.
Note
In the first testcase, it's possible to make using carriage return operations.
In the second testcase, it is possible to make with the minimal number of carriage returns as follows:
If Misuki is using the first typewriter:
- Write number: write to , becomes
- Move pointer: move the pointer to the next position. (i.e. )
- Write number: write to , becomes
If Misuki is using the second typewriter:
- Move pointer: move the pointer to the next position. (i.e. )
- Write number: write to , becomes
- Carriage return: return the pointer to .
- Write number: write to , becomes
It can be proven that the minimum number of carriage returns needed to transform into when using the first typewriter is and it is when using the second one, so this permutation is not valid.
Similarly, is also not valid, so there is no solution for .
In the third testcase, it is possibile to make with carriage return with both the first and the second typewriter. It can be proven that, for both typewriters, it is impossible to write with carriage returns.
With the first typewriter it is possible to:
- Move pointer: move the pointer to the next position. (i.e. )
- Write number: write to , becomes
- Move pointer: move the pointer to the next position. (i.e. )
- Write number: write to , becomes
- Carriage return: return the pointer to .
- Write number: write to , becomes
With the second typewriter it is possible to:
- Move pointer: move the pointer to the next position. (i.e. )
- Write number: write to , becomes
- Carriage return: return the pointer to .
- Write number: write to , becomes
- Move pointer: move the pointer to the next position. (i.e. )
- Move pointer: move the pointer to the next position. (i.e. )
- Write number: write to , becomes
Samples
3
1
2
3
1
-1
3 1 2
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |