CF1582D.Vupsen, Pupsen and 0

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vupsen and Pupsen were gifted an integer array. Since Vupsen doesn't like the number 00, he threw away all numbers equal to 00 from the array. As a result, he got an array aa of length nn.

Pupsen, on the contrary, likes the number 00 and he got upset when he saw the array without zeroes. To cheer Pupsen up, Vupsen decided to come up with another array bb of length nn such that ∑i=1nai⋅bi=0\sum_{i=1}^{n}a_i \cdot b_i=0. Since Vupsen doesn't like number 00, the array bb must not contain numbers equal to 00. Also, the numbers in that array must not be huge, so the sum of their absolute values cannot exceed 10910^9. Please help Vupsen to find any such array bb!

乌普森和普普森收到了一个整数数组。由于乌普森不喜欢数字 00,他将原数组中所有等于 00 的数都扔掉了。结果,他得到了一个长度为 nn 的数组 aa。

而普普森恰恰相反,他喜欢数字 00;当他看到这个不含 00 的数组时,感到很沮丧。为了安慰普普森,乌普森决定构造另一个长度为 nn 的数组 bb,使得 ∑i=1nai⋅bi=0\sum_{i=1}^{n}a_i \cdot b_i=0。又因为乌普森不喜欢数字 00,所以数组 bb 中不能包含任何等于 00 的数。此外,这些数也不能过大,即它们的绝对值之和不得超过 10910^9。请帮乌普森找出任意一个满足上述条件的数组 bb!

输入格式

The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. The next 2⋅t2 \cdot t lines contain the description of test cases. The description of each test case consists of two lines.

The first line of each test case contains a single integer nn (2≤n≤1052 \le n \le 10^5) — the length of the array.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−104≤ai≤104-10^4 \le a_i \le 10^4, ai≠0a_i \neq 0) — the elements of the array aa.

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

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。接下来的 2⋅t2 \cdot t 行包含测试用例的描述。每个测试用例的描述由两行组成。

每个测试用例的第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5),表示数组的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−104≤ai≤104-10^4 \le a_i \le 10^4,且 ai≠0a_i \neq 0),表示数组 aa 的元素。

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

输出格式

For each test case print nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n — elements of the array bb (∣b1∣+∣b2∣+…+∣bn∣≤109|b_1|+|b_2|+\ldots +|b_n| \le 10^9, bi≠0b_i \neq 0, ∑i=1nai⋅bi=0\sum_{i=1}^{n}a_i \cdot b_i=0).

It can be shown that the answer always exists.

对于每个测试用例,输出 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n —— 数组 bb 的元素(满足 ∣b1∣+∣b2∣+…+∣bn∣≤109|b_1|+|b_2|+\ldots +|b_n| \le 10^9,bi≠0b_i \neq 0,且 ∑i=1nai⋅bi=0\sum_{i=1}^{n}a_i \cdot b_i=0)。

可以证明答案一定存在。

输入输出样例

  • 输入#1

    3
    2
    5 5
    5
    5 -2 10 -9 4
    7
    1 2 3 4 5 6 7

    输出#1

    1 -1
    -1 5 1 -1 -1
    -10 2 2 -3 5 -1 -1

说明/提示

In the first test case, 5⋅1+5⋅(−1)=5−5=05 \cdot 1 + 5 \cdot (-1)=5-5=0. You could also print 33 −3-3, for example, since 5⋅3+5⋅(−3)=15−15=05 \cdot 3 + 5 \cdot (-3)=15-15=0

In the second test case, 5⋅(−1)+(−2)⋅5+10⋅1+(−9)⋅(−1)+4⋅(−1)=−5−10+10+9−4=05 \cdot (-1) + (-2) \cdot 5 + 10 \cdot 1 + (-9) \cdot (-1) + 4 \cdot (-1)=-5-10+10+9-4=0.

在第一个测试用例中,5⋅1+5⋅(−1)=5−5=05 \cdot 1 + 5 \cdot (-1)=5-5=0。你也可以输出 33 −3-3,例如,因为 5⋅3+5⋅(−3)=15−15=05 \cdot 3 + 5 \cdot (-3)=15-15=0。

在第二个测试用例中,5⋅(−1)+(−2)⋅5+10⋅1+(−9)⋅(−1)+4⋅(−1)=−5−10+10+9−4=05 \cdot (-1) + (-2) \cdot 5 + 10 \cdot 1 + (-9) \cdot (-1) + 4 \cdot (-1)=-5-10+10+9-4=0。

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

首页