P21259 [CodeChef] EQLIS
提高-
题目描述

For a permutation P of length N, we define L(P) to be the length of the longest increasing subsequence in P. That is, L(P) is the largest integer K such that there exist indices $i_{1} < i_{2} < \ldots < i_{K}$ such that $P_{i_{1}} < P_{i_{2}} < \ldots < P_{i_{K}}$.

Define P^{R} to be the permutation $(P_{N}, P_{N-1}, \ldots, P_{1})$.

You are given a positive integer N. You need to output a permutation P of length N such that L(P) = L(P^{R}), or say that none exist.

Note: P is said to be a permutation of length N if P is a sequence of length N consisting of N distinct integers between 1 and N. For example, (3, 1, 2) is a permutation of length 3, but (1, 4, 2), (2, 2, 3) and (2, 1) are not.

------ Input Format ------

  • The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
  • Each test case consists of a single line containing one integer N — the length of the permutation to be constructed.

------ Output Format ------

For each test case, output on a new line "YES" if there exists a valid permutation, and "NO" if there doesn't. If you outputted "YES", on the next line, output a valid permutation P as N space-separated integers, the i^{th} of which is P_{i}.

You can print each letter of the string in any case (upper or lower) (for instance, strings YES, yEs, and yes will be considered identical).

------ Constraints ------

$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 2 \cdot 10^{5}$
- The sum of $N$ across all test cases does not exceed $2 \cdot 10^{5}$

----- Sample Input 1 ------
2
2
3
----- Sample Output 1 ------
NO
YES
1 3 2
----- explanation 1 ------
Test Case $1$: There are two permutations of length $2$ — $(1, 2)$ and $(2, 1)$. The length of the LIS of $(1, 2)$ is $2$ and the length of the LIS of $(2, 1)$ is $1$. Since these permutations are reverses of each other and have unequal LIS lengths, there is no valid permutation of length $2$.

Test Case $2$: The length of the LIS of $(1, 3, 2)$ is $2$, and the length of the LIS of its reverse, $(2, 3, 1)$, is also $2$. Therefore, this is a valid permutation of length $3$.

输入格式

见题面

输出格式

见题面

样例输入
2 2 3
样例输出
NO YES 1 3 2