Codeforces Round 983 (Div. 2)
E
Balanced
Codeforces
2400
原题
← DF →
翻译中…

You are given a cyclic array $a$ with $n$ elements, where $n$ is odd. In each operation, you can do the following:

翻译中…
  • Choose an index $1 \le i \le n$ and increase $a_{i - 1}$ by $1$, $a_i$ by $2$, and $a_{i + 1}$ by $1$. The element before the first element is the last element because this is a cyclic array.
翻译中…

A cyclic array is called balanced if all its elements are equal to each other.

翻译中…

Find any sequence of operations to make this cyclic array balanced or determine that it is impossible. Please note that you do not have to minimize the number of operations.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 2 \cdot 10^5$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \lt 2 \cdot 10^5$, $n$ is odd) — the length of the array $a$.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^{6}$) — the elements of the array $a$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case:

翻译中…
  • If it is impossible to make the cyclic array balanced, output $-1$.
  • Otherwise, output $n$ integers $v_1, v_2, \ldots, v_n$ ($0 \leq v_i \leq 10^{18}$) — where $v_i$ denotes the number of operations applied to index $i$. It can be proved that if any solution exists, then there exists a solution under the given constraints. If there are several solutions under the given constraints, output any of them.
翻译中…

Note

翻译中…

In the first test case:

翻译中…
  • After $1$ operation applied to index $i = 2$, the array $a = [3, 3, 3]$.
翻译中…

In the second test case:

翻译中…
  • After $2$ operations applied to index $i = 1$, the array $a = [5, 4, 5]$.
  • After $1$ operation applied to index $i = 2$, the array $a = [6, 6, 6]$.
翻译中…

In the third test case:

翻译中…
  • After $2$ operations applied to index $i = 1$, the array $a = [5, 4, 1, 2, 3]$.
  • After $3$ operations applied to index $i = 3$, the array $a = [5, 7, 7, 5, 3]$.
  • After $2$ operations applied to index $i = 5$, the array $a = [7, 7, 7, 7, 7]$.
翻译中…

样例

Input #1
6
3
2 1 2
3
1 2 3
5
1 2 1 2 1
7
1 2 1 2 1 3 1
9
10000 10000 10000 10000 10000 10001 10002 10001 10000
1
10
Output #1
0 1 0
2 1 0
2 0 3 0 2
4 2 7 0 8 0 6
1 1 1 1 1 1 0 1 1
0
InputCopy OutputCopy
题目信息
题号
2032E
时间限制
2 s
内存限制
256 MB
标签
构造
数据结构
贪心
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。