#P16121. [USTCPC 2026] Is it paired?
[USTCPC 2026] Is it paired?
Background
Kruskal-chan invites you to construct one!
Kruskal-chan has an integer array of length . She is thinking: how nice it would be if all subarrays of could be paired up, and the two subarrays in each pair have equal sums!
Kruskal-chan thought of the all-zero array. That seems a bit too easy! So she does not allow zeros in the array anymore. Can you help her construct an array that satisfies the requirements?
Problem Description
Given , construct an integer array of length such that:
- For , and .
- Put the sums of all subarrays of array into a multiset . The number of occurrences of every element in must be even.
If no construction exists, output followed by a newline to indicate there is no solution. If there are multiple constructions, output any one of them.
Note: A subarray means selecting some consecutive elements in an array to form a new array. A subarray contains at least one element.
Input Format
This problem has multiple test cases.
The first line contains a positive integer , the number of test cases.
The next lines each contain an integer , the length of the array to construct.
Output Format
Output a total of lines, each line giving an answer for one .
If no construction exists, output an integer and a newline.
Otherwise, output integers separated by spaces on one line and end with a newline, representing your construction.
Note that your construction must satisfy .
2
6
8
0
-5 6 2 -5 3 2 -3 -5
Hint
Suppose the constructed array is {1,2,2,3}. First compute the sums of all subarrays:
- Subarrays of length 1: 1, 2, 2, 3
- Subarrays of length 2: 3, 4, 5
- Subarrays of length 3: 5, 7
- Subarrays of length 4: 8
Put these subarray sums into multiset ,得到 . Element 1 appears 1 time, element 2 appears 2 times, element 3 appears 2 times, element 4 appears 1 time, element 5 appears 2 times, element 7 appears 1 time, and element 8 appears 1 time. Since the occurrence counts of elements 1, 4, 7, and 8 are odd, this array does not satisfy the requirements.
Translated by ChatGPT 5