luogu#P8278. 「MCOI-08」Fill In

    ID: 7225 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>洛谷原创Special JudgeO2优化前缀和洛谷月赛

「MCOI-08」Fill In

Background

$$\begin{aligned}\text{sdjvlajdiofjoiw{\color{1f1e33}n}eglaj}\\\text{pcji{\color{1f1e33}2}gweiruitowoeuri}\\\text{cnvak{\color{1f1e33}5}jflkjweirqoiru}\\\text{rrrwei{\color{1f1e33}f}dlskfjqfafdfaff}\\\text{nmslfjwiejfijlxkjfq{\color{1f1e33}b}el}\\\text{mmm{\color{1f1e33}b}fsfmkdfmksld}\\\text{erjf{\color{1f1e33}n}kerjkwerjkwjeri}\\\text{sdfafafaf{\color{1f1e33}r}fxvzxvzvzx}\end{aligned}$$

Problem Description

Dream has an array of positive integers a1,a2,,ana_1, a_2, \dots, a_n of length nn (1n1051 \le n \le 10^5). For i=1,2,,ni = 1, 2, \dots, n, it satisfies 1ai10001 \le a_i \le 1000.

He computed the prefix sum array pi=a1+a2++aip_i = a_1 + a_2 + \dots + a_i, and it is guaranteed that in the original prefix sum array, for any 1i<n1 \le i < n, we have pi<pi+1p_i < p_{i+1}.

Now Tommy stole this array and replaced some elements of pp with 1-1. Given the current array pp, restore any valid a1,a2,,ana_1, a_2, \dots, a_n. It can be proven that there is always at least one array aia_i that satisfies the requirements.

Input Format

This problem contains multiple test cases. The first line contains a positive integer tt, the number of test cases. Then follow tt test cases. For each test case:

The first line contains an integer nn.

The second line contains nn integers pip_i, representing the prefix sum sequence.

Output Format

For each test case:

Output one line with nn integers, representing one array aia_i that satisfies the requirements.

2
5
10 -1 20 -1 30
6
-1 -1 -1 -1 -1 -1
10 5 5 5 5
1 1 4 5 1 4

Hint

Explanation for Sample 1

The output sequence aia_i must satisfy the conditions:

  • p1=10=a1p_1 = 10 = a_1;
  • p3=20=a1+a2+a3p_3 = 20 = a_1 + a_2 + a_3;
  • p5=30=a1+a2+a3+a4+a5p_5 = 30 = a_1 + a_2 + a_3 + a_4 + a_5.

Constraints

For 100%100\% of the testdata, 1n,n1051 \le n, \sum n \le 10^5, and it is guaranteed that there exists at least one valid array aa.

  • Subtask 1 (50 pts): For i=1,2,,ni = 1, 2, \dots, n, pi1p_i \neq -1;
  • Subtask 2 (30 pts): It is guaranteed that there does not exist an ii such that pi=pi+1=1p_i = p_{i+1} = -1;
  • Subtask 3 (20 pts): No special restrictions.

Translated by ChatGPT 5