CF1857E.Power of Points
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given n points with integer coordinates x1,…xn , which lie on a number line.
For some integer s , we construct segments [ s,x1 ], [ s,x2 ], … , [ s,xn ]. Note that if xi<s , then the segment will look like [ xi,s ]. The segment [ a,b ] covers all integer points a,a+1,a+2,…,b .
We define the power of a point p as the number of segments that intersect the point with coordinate p , denoted as fp .
Your task is to compute p=1∑109fp for each s∈{x1,…,xn} , i.e., the sum of fp for all integer points from 1 to 109 .
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: f1=2,f2=3,f3=3,f4=3,f5=5,f6=1,f7=1,f8=0,…,f109=0 . Their sum is 2+3+3+3+5+1+1=18 .
输入格式
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 number of points.
The second line contains n integers x1,x2…xn ( 1≤xi≤109 ) — the coordinates of the points.
It is guaranteed that the sum of the values of n over all test cases does not exceed 2⋅105 .
输出格式
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=xi .
输入输出样例
输入#1
3 3 1 4 3 5 1 2 5 7 1 4 1 10 100 1000
输出#1
8 7 6 16 15 18 24 16 1111 1093 1093 2893
说明/提示
In the first test case we first choose s=x1=1 , then the following segments are formed: [1,1] , [1,4] , [1,3] .
The powers of the points will be as follows: f1=3,f2=2,f3=2,f4=1,f5=0… The sum of powers of the points: 3+2+2+1+0+⋯+0=8 .
After that we choose s=x2=4 . Then there will be such segments: [1,4] , [4,4] , [3,4] , and powers of the points are f1=1,f2=1,f3=2,f4=3 .
At the end we take s=x3=3 and the segments look like this: [1,3] , [3,4] , [3,3] , the powers of the points are f1=1,f2=1,f3=3,f4=1 .