CF2254D.Silhouette
普及-
通过率:0%
时间限制:2.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yousef has a secret array a of n strictly positive integers.
For each element ai, its shadow bi is the sum of all elements in a that are strictly smaller than ai. Formally:
b_i=sum_substack1lejlena_jlta_ia_j
You are given the shadow array b. Your task is to reconstruct the lexicographically smallest valid array a consisting of strictly positive integers that satisfies the above condition. If no such array exists, output −1.
优素福有一个长度为 n 的秘密数组 a,其中所有元素均为严格正整数。
对每个元素 ai,其“影子” bi 定义为数组 a 中所有严格小于 ai 的元素之和。形式化地:
b_i=sum_substack1lejlena_jlta_ia_j
你被给定了影子数组 b。你的任务是重构出字典序最小的、由严格正整数组成的有效数组 a,使其满足上述条件。若不存在这样的数组,则输出 −1。
输入格式
The first line contains an integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains an integer n (1≤n≤2⋅105) — the size of the array.
The second line of each test case contains n integers b1,b2,…,bn (0≤bi≤2⋅1014) — the shadow array.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)——数组的大小。
每个测试用例的第二行包含 n 个整数 b1,b2,…,bn(0≤bi≤2⋅1014)——影子数组。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output n integers a1,a2,…,an (1≤ai≤1018) — the lexicographically smallest valid array a that satisfies the condition. If no valid array exists, output −1 instead.
对于每个测试用例,输出 n 个整数 a1,a2,…,an(1≤ai≤1018)——满足条件的字典序最小的有效数组 a。如果不存在有效数组,则输出 −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]. Since there is only one element, there are no strictly smaller elements, so its shadow is 0. Thus a=[1] is valid. It is also lexicographically smallest, because the only allowed values are positive integers, and 1 is the smallest possible.
In the second test case, the answer is a=[2,5,2,5,6]:
- For each 2, there is no smaller element in the array, so the shadow is 0.
- For each 5, the strictly smaller elements are the two 2's, so the shadow is 2+2=4.
- For 6, the strictly smaller elements are two 2's and two 5's, so the shadow is 2+2+5+5=14.
Therefore the shadow array is exactly b=[0,4,0,4,14].
In the third test case, the shadow array for a=[3,2,2] is calculated as follows:
- For a1=3, the strictly smaller elements in the array are the two 2s. Their sum is 2+2=4. So, b1=4.
- For a2=2, there are no strictly smaller elements in the array. So, b2=0.
- For a3=2, there are no strictly smaller elements in the array. So, b3=0.
The resulting shadow array is b=[4,0,0], which matches the input.
在第一个测试用例中,答案为 a=[1]。由于数组中仅有一个元素,因此不存在严格更小的元素,其阴影值为 0。因此 a=[1] 是合法的。同时它也是字典序最小的,因为允许的取值仅为正整数,而 1 是可能的最小值。
在第二个测试用例中,答案为 a=[2,5,2,5,6]:
- 对于每个 2,数组中不存在更小的元素,因此其阴影值为 0。
- 对于每个 5,数组中严格更小的元素是两个 2,因此其阴影值为 2+2=4。
- 对于 6,数组中严格更小的元素是两个 2 和两个 5,因此其阴影值为 2+2+5+5=14。
因此得到的阴影数组恰好为 b=[0,4,0,4,14]。
在第三个测试用例中,对 a=[3,2,2] 计算其阴影数组如下:
- 对于 a1=3,数组中严格更小的元素是两个 2,它们的和为 2+2=4,故 b1=4。
- 对于 a2=2,数组中不存在严格更小的元素,故 b2=0。
- 对于 a3=2,数组中不存在严格更小的元素,故 b3=0。
最终得到的阴影数组为 b=[4,0,0],与输入一致。
输入解题思路,AI测评打分。不知道怎么写?