CF1598C.Delete Two Elements

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Monocarp has got an array aa consisting of nn integers. Let's denote kk as the mathematic mean of these elements (note that it's possible that kk is not an integer).

The mathematic mean of an array of nn elements is the sum of elements divided by the number of these elements (i. e. sum divided by nn).

Monocarp wants to delete exactly two elements from aa so that the mathematic mean of the remaining (n−2)(n - 2) elements is still equal to kk.

Your task is to calculate the number of pairs of positions [i,j][i, j] (i<ji \lt j) such that if the elements on these positions are deleted, the mathematic mean of (n−2)(n - 2) remaining elements is equal to kk (that is, it is equal to the mathematic mean of nn elements of the original array aa).

Monocarp 得到了一个由 nn 个整数组成的数组 aa。记 kk 为这些元素的算术平均值(注意:kk 可能不是整数)。

一个包含 nn 个元素的数组的算术平均值,等于这些元素之和除以元素个数(即和除以 nn)。

Monocarp 想要恰好从 aa 中删除两个元素,使得剩余 (n−2)(n - 2) 个元素的算术平均值仍等于 kk。

你的任务是计算满足如下条件的位置对 [i,j][i, j](其中 i<ji \lt j)的个数:若删除位于位置 ii 和 jj 上的元素,则剩余 (n−2)(n - 2) 个元素的算术平均值等于 kk(即等于原数组 aa 的 nn 个元素的算术平均值)。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of testcases.

The first line of each testcase contains one integer nn (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5) — the number of elements in the array.

The second line contains a sequence of integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤1090 \le a_i \le 10^{9}), where aia_i is the ii-th element of the array.

The sum of nn over all testcases doesn't exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含一个整数 nn(3≤n≤2⋅1053 \le n \le 2 \cdot 10^5)—— 数组中元素的个数。

第二行包含一个整数序列 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤1090 \le a_i \le 10^{9}),其中 aia_i 表示数组的第 ii 个元素。

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

输出格式

Print one integer — the number of pairs of positions [i,j][i, j] (i<ji \lt j) such that if the elements on these positions are deleted, the mathematic mean of (n−2)(n - 2) remaining elements is equal to kk (that is, it is equal to the mathematic mean of nn elements of the original array aa).

输出一个整数——满足条件的下标对 [i,j][i, j](其中 i<ji \lt j)的个数:若删除这两个位置上的元素,则剩余 (n−2)(n - 2) 个元素的算术平均值等于 kk(即等于原数组 aa 中 nn 个元素的算术平均值)。

输入输出样例

  • 输入#1

    4
    4
    8 8 8 8
    3
    50 20 10
    5
    1 4 7 3 5
    7
    1 2 3 4 5 6 7

    输出#1

    6
    0
    2
    3

说明/提示

In the first example, any pair of elements can be removed since all of them are equal.

In the second example, there is no way to delete two elements so the mathematic mean doesn't change.

In the third example, it is possible to delete the elements on positions 11 and 33, or the elements on positions 44 and 55.

在第一个例子中,任意一对元素都可以被删除,因为所有元素都相等。

在第二个例子中,不存在删除两个元素使得算术平均值不变的方法。

在第三个例子中,可以删除位置 11 和 33 上的元素,或者删除位置 44 和 55 上的元素。

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

首页