CF1857E.Power of Points

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given nn points with integer coordinates x1,xnx_1,\dots x_n , which lie on a number line.

For some integer ss , we construct segments [ s,x1s,x_1 ], [ s,x2s,x_2 ], \dots , [ s,xns,x_n ]. Note that if xi<sx_i<s , then the segment will look like [ xi,sx_i,s ]. The segment [ a,ba, b ] covers all integer points a,a+1,a+2,,ba, a+1, a+2, \dots, b .

We define the power of a point pp as the number of segments that intersect the point with coordinate pp , denoted as fpf_p .

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

For example, if the initial coordinates are [1,2,5,7,1][1,2,5,7,1] and we choose s=5s=5 , then the segments will be: [1,5][1,5] , [2,5][2,5] , [5,5][5,5] , [5,7][5,7] , [1,5][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=0f_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=182+3+3+3+5+1+1=18 .

输入格式

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

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

The second line contains nn integers x1,x2xnx_1,x_2 \dots x_n ( 1xi1091 \le x_i \le 10^9 ) — the coordinates of the points.

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

输出格式

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

输入输出样例

  • 输入#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=1s=x_1=1 , then the following segments are formed: [1,1][1,1] , [1,4][1,4] , [1,3][1,3] .

The powers of the points will be as follows: f1=3,f2=2,f3=2,f4=1,f5=0f_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++0=83+2+2+1+0+\dots+0=8 .

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

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

首页