#P16394. [ECUSTPC 2026 Spring] 回响形态
[ECUSTPC 2026 Spring] 回响形态
Background
:::epigraph Did you manage to construct the sequence?
You managed to construct the sequence. :::
Problem Description
The Construction Kingdom is still chasing Little T……
For a sequence of length , define its prefix sequence as , and its prefix sequence as .
Given and , please construct two sequences and of length that satisfy the following conditions. If no such two sequences exist, report that there is no solution:
- and are permutations of to .
- and differ in at least one position, i.e., there exists such that .
- For either sequence among and , let its prefix sequence be and prefix sequence be . It must satisfy:
Input Format
The first line contains an integer , denoting the number of testdata.
Each testdata contains one line with two integers and , denoting the length of the sequence and the difference between the prefix and prefix .
It is guaranteed that over all testdata.
Output Format
For each testdata, if there exist two sequences that satisfy the conditions, output two lines.
The first line outputs integers , representing the first sequence you constructed.
The next line outputs integers , representing the second sequence .
If no such two sequences exist, output one line containing a single integer .
If there are multiple valid answers, you may output any one of them.
3
2 1
2 0
5 12
1 2
2 1
-1
1 3 4 2 5
1 2 4 5 3
Hint
Sample 1 Explanation
For the 3rd testdata, we verify whether the second sequence, i.e. sequence , satisfies the conditions:
- is a permutation of to , because each integer appears exactly once.
- The second element is , , and .
- Its prefix sequence is , and its prefix sequence is . Thus,
Hint
A permutation of to is a sequence of length in which each integer from to appears exactly once.
Translated by ChatGPT 5