Codeforces Round 1030 (Div. 2)
B
Make It Permutation
Codeforces
1200
原题
← AC →
翻译中…

There is a matrix $A$ of size $n\times n$ where $A_{i,j}=j$ for all $1 \le i,j \le n$.

翻译中…

In one operation, you can select a row and reverse any subarray$^{\text{∗}}$ in it.

翻译中…

Find a sequence of at most $2n$ operations such that every column will contain a permutation$^{\text{†}}$ of length $n$.

翻译中…

It can be proven that the construction is always possible. If there are multiple solutions, output any of them.

翻译中…

$^{\text{∗}}$An array $a$ is a subarray of an array $b$ if $a$ can be obtained from $b$ by deleting zero or more elements from the beginning and zero or more elements from the end.$^{\text{†}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.

翻译中…

The first line of each test case contains one integer $n$ ($3 \le n \le 5000$) — denoting the number of rows and columns in the matrix.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$.

翻译中…

Output

翻译中…

For each test case, on the first line, print an integer $k$ $(0 \le k \le 2n)$, the number of operations you wish to perform. On the next lines, you should print the operations.

翻译中…

To print an operation, use the format "$i\;l\;r$" ($1 \leq l \leq r \leq n$ and $1 \leq i \leq n$) which reverses the subarray $A_{i, l}$, $A_{i, l+1}$, $\ldots$, $A_{i, r}$.

翻译中…

Note

翻译中…

In the first test case, the following operations are a valid solution:

翻译中…

image

翻译中…

样例

Input #1
2
3
4
Output #1
4
2 1 3
2 2 3
3 1 2
3 2 3
5
2 1 4
3 1 3
3 2 4
4 3 4
4 1 2
InputCopy OutputCopy
题目信息
题号
2118B
时间限制
1 s
内存限制
256 MB
标签
构造

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。