P16394 [ECUSTPC 2026 Spring] Echo Form
Background
:::epigraph
Did you manage to construct the sequence?
You managed to construct the sequence.
:::
Description
The Construction Kingdom is still chasing Little T……
For a sequence of length $n$, define its prefix $\max$ sequence $x$ as $x_i = \max\{a_j : 1 \le j \le i\}$, and its prefix $\min$ sequence $y$ as $y_i = \min\{a_j : 1 \le j \le i\}$.
Given $n$ and $k$, please construct two sequences $a$ and $b$ of length $n$ that satisfy the following conditions. If no such two sequences exist, report that there is no solution:
- $a$ and $b$ are permutations of $1$ to $n$.
- $a$ and $b$ differ in at least one position, i.e., there exists $i$ such that $a_i \ne b_i$.
- For either sequence among $a$ and $b$, let its prefix $\max$ sequence be $x$ and prefix $\min$ sequence be $y$. It must satisfy:
$$
\sum_{i=1}^{n}(x_i - y_i) = k.
$$
Input Format
The first line contains an integer $T \ (1 \le T \le 10^5)$, denoting the number of testdata.
Each testdata contains one line with two integers $n$ and $k \ (2 \le n \le 10^5, 0 \le k \le 10^{10})$, denoting the length of the sequence and the difference between the prefix $\max$ and prefix $\min$.
It is guaranteed that $\sum n \le 3 \times 10^5$ over all testdata.
Output Format
For each testdata, if there exist two sequences that satisfy the conditions, output two lines.
The first line outputs $n$ integers $a_1, a_2, \dots, a_n$, representing the first sequence $a$ you constructed.
The next line outputs $n$ integers $b_1, b_2, \dots, b_n$, representing the second sequence $b$.
If no such two sequences exist, output one line containing a single integer $-1$.
If there are multiple valid answers, you may output any one of them.
Explanation/Hint
### Sample 1 Explanation
For the 3rd testdata, we verify whether the second sequence, i.e. sequence $b$, satisfies the conditions:
- $\{1, 2, 4, 5, 3\}$ is a permutation of $1$ to $5$, because each integer appears exactly once.
- The second element is $a_2 = 3$, $b_2 = 2$, and $a_2 \ne b_2$.
- Its prefix $\max$ sequence is $x = \{1, 2, 4, 5, 5\}$, and its prefix $\min$ sequence is $y = \{1, 1, 1, 1, 1\}$. Thus,
$$
\sum_{i=1}^{n}(x_i - y_i) = (1 - 1) + (2 - 1) + (4 - 1) + (5 - 1) + (5 - 1) = 0 + 1 + 3 + 4 + 4 = 12 = k.
$$
### Hint
A permutation of $1$ to $n$ is a sequence of length $n$ in which each integer from $1$ to $n$ appears exactly once.
Translated by ChatGPT 5