CF2254D.Silhouette

普及-

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Yousef has a secret array aa of nn strictly positive integers.

For each element aia_i, its shadow bib_i is the sum of all elements in aa that are strictly smaller than aia_i. Formally:

b_i=sum_substack1lejlena_jlta_ia_jb\_i = \\sum\_{\\substack{1 \\le j \\le n\\\\ a\_j \\lt a\_i}} a\_j

You are given the shadow array bb. Your task is to reconstruct the lexicographically smallest valid array aa consisting of strictly positive integers that satisfies the above condition. If no such array exists, output −1-1.

优素福有一个长度为 nn 的秘密数组 aa,其中所有元素均为严格正整数。

对每个元素 aia_i,其“影子” bib_i 定义为数组 aa 中所有严格小于 aia_i 的元素之和。形式化地:

b_i=sum_substack1lejlena_jlta_ia_jb\_i = \\sum\_{\\substack{1 \\le j \\le n\\\\ a\_j \\lt a\_i}} a\_j

你被给定了影子数组 bb。你的任务是重构出字典序最小的、由严格正整数组成的有效数组 aa,使其满足上述条件。若不存在这样的数组,则输出 −1-1。

输入格式

The first line contains an integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains an integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the size of the array.

The second line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n (0≤bi≤2⋅10140 \le b_i \le 2 \cdot 10^{14}) — the shadow array.

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

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)——数组的大小。

每个测试用例的第二行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(0≤bi≤2⋅10140 \le b_i \le 2 \cdot 10^{14})——影子数组。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤10181 \le a_i \le 10^{18}) — the lexicographically smallest valid array aa that satisfies the condition. If no valid array exists, output −1-1 instead.

对于每个测试用例,输出 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤10181 \le a_i \le 10^{18})——满足条件的字典序最小的有效数组 aa。如果不存在有效数组,则输出 −1-1。

输入输出样例

  • 输入#1

    8
    1
    0
    5
    0 4 0 4 14
    3
    4 0 0
    3
    0 0 0
    3
    0 1 1
    4
    1 1 1 1
    7
    0 4 4 4 4 4 9
    5
    0 0 0 3 3

    输出#1

    1
    2 5 2 5 6
    3 2 2
    1 1 1
    1 2 2
    -1
    -1
    1 1 1 2 2

说明/提示

In the first test case, the answer is a=[1]a = [1]. Since there is only one element, there are no strictly smaller elements, so its shadow is 00. Thus a=[1]a=[1] is valid. It is also lexicographically smallest, because the only allowed values are positive integers, and 11 is the smallest possible.

In the second test case, the answer is a=[2,5,2,5,6]a = [2,5,2,5,6]:

  • For each 22, there is no smaller element in the array, so the shadow is 00.
  • For each 55, the strictly smaller elements are the two 22's, so the shadow is 2+2=42+2=4.
  • For 66, the strictly smaller elements are two 22's and two 55's, so the shadow is 2+2+5+5=142+2+5+5=14.

Therefore the shadow array is exactly b=[0,4,0,4,14]b = [0,4,0,4,14].

In the third test case, the shadow array for a=[3,2,2]a = [3, 2, 2] is calculated as follows:

  • For a1=3a_1 = 3, the strictly smaller elements in the array are the two 22s. Their sum is 2+2=42 + 2 = 4. So, b1=4b_1 = 4.
  • For a2=2a_2 = 2, there are no strictly smaller elements in the array. So, b2=0b_2 = 0.
  • For a3=2a_3 = 2, there are no strictly smaller elements in the array. So, b3=0b_3 = 0.

The resulting shadow array is b=[4,0,0]b = [4, 0, 0], which matches the input.

在第一个测试用例中,答案为 a=[1]a = [1]。由于数组中仅有一个元素,因此不存在严格更小的元素,其阴影值为 00。因此 a=[1]a=[1] 是合法的。同时它也是字典序最小的,因为允许的取值仅为正整数,而 11 是可能的最小值。

在第二个测试用例中,答案为 a=[2,5,2,5,6]a = [2,5,2,5,6]:

  • 对于每个 22,数组中不存在更小的元素,因此其阴影值为 00。
  • 对于每个 55,数组中严格更小的元素是两个 22,因此其阴影值为 2+2=42+2=4。
  • 对于 66,数组中严格更小的元素是两个 22 和两个 55,因此其阴影值为 2+2+5+5=142+2+5+5=14。

因此得到的阴影数组恰好为 b=[0,4,0,4,14]b = [0,4,0,4,14]。

在第三个测试用例中,对 a=[3,2,2]a = [3, 2, 2] 计算其阴影数组如下:

  • 对于 a1=3a_1 = 3,数组中严格更小的元素是两个 22,它们的和为 2+2=42 + 2 = 4,故 b1=4b_1 = 4。
  • 对于 a2=2a_2 = 2,数组中不存在严格更小的元素,故 b2=0b_2 = 0。
  • 对于 a3=2a_3 = 2,数组中不存在严格更小的元素,故 b3=0b_3 = 0。

最终得到的阴影数组为 b=[4,0,0]b = [4, 0, 0],与输入一致。

输入解题思路,AI测评打分。不知道怎么写?

首页