P16628 [CodeChef] PER MED
普及-
题目描述

Given a sequence of N elements, Chef defines a function F(i) (1 ≤ i ≤ N) as the median of the first i elements of the sequence.

Chef wants to get a permutation P of length N such that $P_{i} = F(i) \forall 1$ ≤ i ≤ N. Can you help Chef in achieving this?

Note that:
The median of a sequence is the middle element in the sorted order of the sequence. If N is even, choose the element at $\frac{N}{2}$ position in the sorted order. If N is odd, choose the middle element.
A permutation of length N is an array of $N integers P = [P_{1}, P_{2}, \ldots, P_{N}]$ such that every integer from 1 to N (inclusive) appears in it exactly once. For example, [2,5,4,1,3] is a permutation of length 5 while [2, 5, 2, 1, 3] is not.

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

  • First line will contain T, number of test cases. Then the test cases follows.
  • Each test case consists of a single line of input, an integer N, the length of the required permutation.

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

For each test case, output in a new line, N space-separated integers, denoting a permutation satisfying the condition.

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

$1 ≤ T ≤ 700$
$1 ≤ N ≤ 10^{5}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.

----- Sample Input 1 ------
3
1
2
3

----- Sample Output 1 ------
1
2 1
3 1 2
----- explanation 1 ------
Test Case $1$: $[1]$ is the only permutation and it satisfies the condition as the median of the sequence $[1]$ is $1$.

Test Case $2$: The possible permutations of length $2$ are $[1, 2]$ and $[2, 1]$. The only permutation that satisfies the condition is $[2, 1]$. Here, $P_{1} = 2 = median([2])$ and $P_{2} = 1 = median([2, 1])$.

Test Case $3$: There are $6$ possible permutations out of which only $[3,1,2]$ satisfies the above condition. Here, $P_{1} = 3 = median([3]), P_{2} = 1 = median([3, 1]),$ and $P_{3} = 2 = median([3, 1, 2])$.

输入格式

见题面

输出格式

见题面

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