CF2195D.Absolute Cinema

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a hidden sequence a1,a2,…,ana_1,a_2,\ldots,a_n of nn integers (n≥2n \ge 2). It is guaranteed that ∣ai∣≤1000|a_i| \le 1000 for all 1≤i≤n1 \le i \le n.

Let's define a function f(x)f(x) as follows:

f(x)=sum_i=1na_icdot∣i−x∣f(x)=\\sum\_{i=1}^n a\_i \\cdot |i-x|

Given nn values f(1),f(2),…,f(n)f(1),f(2),\ldots,f(n), please determine the values of a1,a2,…,ana_1,a_2,\ldots,a_n.

It is guaranteed that the values a1,a2,…,ana_1,a_2,\ldots,a_n can be determined uniquely.

存在一个隐藏的整数序列 a1,a2,…,ana_1,a_2,\ldots,a_n(其中 n≥2n \ge 2)。保证对所有 1≤i≤n1 \le i \le n,均有 ∣ai∣≤1000|a_i| \le 1000。

我们定义函数 f(x)f(x) 如下:

f(x)=∑i=1nai⋅∣i−x∣f(x)=\sum_{i=1}^n a_i \cdot |i-x|

给定 nn 个值 f(1),f(2),…,f(n)f(1),f(2),\ldots,f(n),请确定 a1,a2,…,ana_1,a_2,\ldots,a_n 的值。

保证 a1,a2,…,ana_1,a_2,\ldots,a_n 的值可被唯一确定。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤300 000\color{red}{2} \le n \le 300\,000).

The second line of each test case contains nn integers f(1),f(2),…,f(n)f(1),f(2),\ldots,f(n) (−1014≤f(i)≤1014-10^{14} \le f(i) \le 10^{14}).

It is guaranteed that the sum of nn over all test cases does not exceed 300 000300\,000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤300 000\color{red}{2} \le n \le 300\,000)。

每个测试用例的第二行包含 nn 个整数 f(1),f(2),…,f(n)f(1),f(2),\ldots,f(n)(−1014≤f(i)≤1014-10^{14} \le f(i) \le 10^{14})。

保证所有测试用例的 nn 之和不超过 300 000300\,000。

输出格式

For each test case, output nn integers a1,a2,…,ana_1,a_2,\ldots,a_n on a separate line (∣ai∣≤1000|a_i| \le 1000).

It is guaranteed that the values a1,a2,…,ana_1,a_2,\ldots,a_n can be determined uniquely.

对于每个测试用例,在单独一行中输出 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(满足 ∣ai∣≤1000|a_i| \le 1000)。

保证 a1,a2,…,ana_1,a_2,\ldots,a_n 的值可以被唯一确定。

输入输出样例

  • 输入#1

    4
    4
    17 9 9 13
    6
    -37 -32 -15 4 27 42
    5
    -26 -32 -24 -4 2
    2
    420 -69

    输出#1

    1 4 2 3
    3 6 1 2 -4 -7
    -6 7 6 -7 -6
    -69 420

说明/提示

In the first test case, the hidden sequence is a=[1,4,2,3]a=[1,4,2,3].

The values f(1),f(2),…,f(n)f(1),f(2),\ldots,f(n) are as follows:

  • f(1)=1⋅∣1−1∣+4⋅∣2−1∣+2⋅∣3−1∣+3⋅∣4−1∣=0+4+4+9=17f(1) = 1 \cdot |1-1| + 4 \cdot |2-1| + 2 \cdot |3-1| + 3 \cdot |4-1| = 0+4+4+9 = 17;
  • f(2)=1⋅∣1−2∣+4⋅∣2−2∣+2⋅∣3−2∣+3⋅∣4−2∣=1+0+2+6=9f(2) = 1 \cdot |1-2| + 4 \cdot |2-2| + 2 \cdot |3-2| + 3 \cdot |4-2| = 1+0+2+6 = 9;
  • f(3)=1⋅∣1−3∣+4⋅∣2−3∣+2⋅∣3−3∣+3⋅∣4−3∣=2+4+0+3=9f(3) = 1 \cdot |1-3| + 4 \cdot |2-3| + 2 \cdot |3-3| + 3 \cdot |4-3| = 2+4+0+3 = 9;
  • f(4)=1⋅∣1−4∣+4⋅∣2−4∣+2⋅∣3−4∣+3⋅∣4−4∣=3+8+2+0=13f(4) = 1 \cdot |1-4| + 4 \cdot |2-4| + 2 \cdot |3-4| + 3 \cdot |4-4| = 3+8+2+0 = 13.

在第一个测试用例中,隐藏序列为 a=[1,4,2,3]a=[1,4,2,3]。

函数值 f(1),f(2),…,f(n)f(1),f(2),\ldots,f(n) 如下:

  • f(1)=1⋅∣1−1∣+4⋅∣2−1∣+2⋅∣3−1∣+3⋅∣4−1∣=0+4+4+9=17f(1) = 1 \cdot |1-1| + 4 \cdot |2-1| + 2 \cdot |3-1| + 3 \cdot |4-1| = 0+4+4+9 = 17;
  • f(2)=1⋅∣1−2∣+4⋅∣2−2∣+2⋅∣3−2∣+3⋅∣4−2∣=1+0+2+6=9f(2) = 1 \cdot |1-2| + 4 \cdot |2-2| + 2 \cdot |3-2| + 3 \cdot |4-2| = 1+0+2+6 = 9;
  • f(3)=1⋅∣1−3∣+4⋅∣2−3∣+2⋅∣3−3∣+3⋅∣4−3∣=2+4+0+3=9f(3) = 1 \cdot |1-3| + 4 \cdot |2-3| + 2 \cdot |3-3| + 3 \cdot |4-3| = 2+4+0+3 = 9;
  • f(4)=1⋅∣1−4∣+4⋅∣2−4∣+2⋅∣3−4∣+3⋅∣4−4∣=3+8+2+0=13f(4) = 1 \cdot |1-4| + 4 \cdot |2-4| + 2 \cdot |3-4| + 3 \cdot |4-4| = 3+8+2+0 = 13。

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

首页