CF1857E.Power of Points

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 \lt 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,…,xns \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.

给你 nn 个具有整数坐标的点 x1,…,xnx_1,\dots,x_n,它们位于一条数轴上。

对某个整数 ss,我们构造线段 [s,x1][s,x_1], [s,x2][s,x_2], …\dots, [s,xn][s,x_n]。注意:若 xi<sx_i < s,则该线段写作 [xi,s][x_i,s]。线段 [a,b][a, b] 覆盖所有整数点 a,a+1,a+2,…,ba, a+1, a+2, \dots, b。

我们定义点 pp 的权值为覆盖坐标 pp 的线段数量,记作 fpf_p。

你的任务是:对每个 s∈{x1,…,xn}s \in \{x_1,\dots,x_n\},计算 ∑p=1109fp\sum\limits_{p=1}^{10^9}f_p,即对从 11 到 10910^9 的所有整数点 pp,求其权值 fpf_p 的总和。

例如,若初始坐标为 [1,2,5,7,1][1,2,5,7,1],且选择 s=5s=5,则所构造的线段为:[1,5][1,5], [2,5][2,5], [5,5][5,5], [5,7][5,7], [1,5][1,5]。各点的权值为:f1=2f_1=2, f2=3f_2=3, f3=3f_3=3, f4=3f_4=3, f5=5f_5=5, f6=1f_6=1, f7=1f_7=1, f8=0f_8=0, …\dots, f109=0f_{10^9}=0。其总和为 2+3+3+3+5+1+1=182+3+3+3+5+1+1=18。

输入格式

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

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

The second line contains nn integers x1,x2…xnx_1,x_2 \dots x_n (1≤xi≤1091 \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 2⋅1052\cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041\le t\le 10^4)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2\cdot 10^5)——点的数量。

每个测试用例的第二行包含 nn 个整数 x1,x2…xnx_1,x_2 \dots x_n(1≤xi≤1091 \le x_i \le 10^9)——各点的坐标。

保证所有测试用例中 nn 的总和不超过 2⋅1052\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.

对于每个测试用例,输出 nn 个整数,其中第 ii 个整数等于当 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=0…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+⋯+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.

在第一个测试用例中,我们首先选择 s=x1=1s=x_1=1,随后形成的区间为:[1,1][1,1]、[1,4][1,4]、[1,3][1,3]。

各点的权值如下:f1=3, f2=2, f3=2, f4=1, f5=0 …f_1=3,\ f_2=2,\ f_3=2,\ f_4=1,\ f_5=0\ \dots。所有点的权值之和为:3+2+2+1+0+⋯+0=83+2+2+1+0+\dots+0=8。

接着我们选择 s=x2=4s=x_2=4,此时形成的区间为:[1,4][1,4]、[4,4][4,4]、[3,4][3,4],各点的权值为 f1=1, f2=1, f3=2, f4=3f_1=1,\ f_2=1,\ f_3=2,\ f_4=3。

最后我们取 s=x3=3s=x_3=3,此时区间为:[1,3][1,3]、[3,4][3,4]、[3,3][3,3],各点的权值为 f1=1, f2=1, f3=3, f4=1f_1=1,\ f_2=1,\ f_3=3,\ f_4=1。

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

首页