#P16121. [USTCPC 2026] Is it paired?

    ID: 18114 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>Special Judge2026高校校赛

[USTCPC 2026] Is it paired?

Background

Kruskal-chan invites you to construct one!

Kruskal-chan has an integer array aa of length nn. She is thinking: how nice it would be if all subarrays of aa 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 nn, construct an integer array aa of length nn such that:

  • For ∀i∈[1,n]\forall i \in [1, n], ai∈[−109,109]a_i \in [-10^9, 10^9] and ai≠0a_i \neq 0.
  • Put the sums of all subarrays of array aa into a multiset SS. The number of occurrences of every element in SS must be even.

If no construction exists, output 00 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 TT (1≤T≤40)(1 \leq T \leq 40), the number of test cases.

The next TT lines each contain an integer nn (1≤n≤1000)(1 \leq n \leq 1000), the length of the array to construct.

Output Format

Output a total of TT lines, each line giving an answer for one nn.

If no construction exists, output an integer 00 and a newline.

Otherwise, output nn integers separated by spaces on one line and end with a newline, representing your construction.

Note that your construction must satisfy a[i]≠0a[i] \neq 0.

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 SS,得到 S={1,2,2,3,3,4,5,5,7,8}S = \{1, 2, 2, 3, 3, 4, 5, 5, 7, 8\}. 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