310598: CF1857E. Power of Points

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Power of Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given $n$ points with integer coordinates $x_1,\dots x_n$, which lie on a number line.

For some integer $s$, we construct segments [$s,x_1$], [$s,x_2$], $\dots$, [$s,x_n$]. Note that if $x_i<s$, then the segment will look like [$x_i,s$]. The segment [$a, b$] covers all integer points $a, a+1, a+2, \dots, b$.

We define the power of a point $p$ as the number of segments that intersect the point with coordinate $p$, denoted as $f_p$.

Your task is to compute $\sum\limits_{p=1}^{10^9}f_p$ for each $s \in \{x_1,\dots,x_n\}$, i.e., the sum of $f_p$ for all integer points from $1$ to $10^9$.

For example, if the initial coordinates are $[1,2,5,7,1]$ and we choose $s=5$, then the segments will be: $[1,5]$,$[2,5]$,$[5,5]$,$[5,7]$,$[1,5]$. And the powers of the points will be: $f_1=2, f_2=3, f_3=3, f_4=3, f_5=5, f_6=1, f_7=1, f_8=0, \dots, f_{10^9}=0$. Their sum is $2+3+3+3+5+1+1=18$.

Input

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

The first line of each test case contains an integer $n$ ($1 \le n \le 2\cdot 10^5$) — the number of points.

The second line contains $n$ integers $x_1,x_2 \dots x_n$ ($1 \le x_i \le 10^9$) — the coordinates of the points.

It is guaranteed that the sum of the values of $n$ over all test cases does not exceed $2\cdot 10^5$.

Output

For each test case, output $n$ integers, where the $i$-th integer is equal to the sum of the powers of all points for $s=x_i$.

ExampleInput
3
3
1 4 3
5
1 2 5 7 1
4
1 10 100 1000
Output
8 7 6
16 15 18 24 16
1111 1093 1093 2893
Note

In the first test case we first choose $s=x_1=1$, then the following segments are formed: $[1,1]$,$[1,4]$,$[1,3]$.

The powers of the points will be as follows: $f_1=3, f_2=2, f_3=2, f_4=1, f_5=0 \dots$ The sum of powers of the points: $3+2+2+1+0+\dots+0=8$.

After that we choose $s=x_2=4$. Then there will be such segments: $[1,4]$,$[4,4]$,$[3,4]$, and powers of the points are $f_1=1, f_2=1, f_3=2, f_4=3$.

At the end we take $s=x_3=3$ and the segments look like this: $[1,3]$,$[3,4]$,$[3,3]$, the powers of the points are $f_1=1, f_2=1, f_3=3, f_4=1$.

Output

题目大意:
给定n个整点坐标x1, ..., xn,它们位于一条数轴上。对于某个整数s,构造线段[s, x1], [s, x2], ..., [s, xn]。如果xi
定义点p的“能量”为穿过坐标为p的点的线段数量,记作fp。

任务是计算每个s属于{x1, ..., xn}的Σfp,即对于所有从1到10^9的整数点的fp之和。

输入输出数据格式:
输入:
第一行包含一个整数t(1≤t≤10^4)——测试用例的数量。
每个测试用例的第一行包含一个整数n(1≤n≤2×10^5)——点的数量。
第二行包含n个整数x1, x2, ..., xn(1≤xi≤10^9)——点的坐标。
保证所有测试用例的n值之和不超过2×10^5。

输出:
对于每个测试用例,输出n个整数,其中第i个整数等于当s=xi时所有点的能量之和。题目大意: 给定n个整点坐标x1, ..., xn,它们位于一条数轴上。对于某个整数s,构造线段[s, x1], [s, x2], ..., [s, xn]。如果xi

加入题单

上一题 下一题 算法标签: