CF1771A.Hossam and Combinatorics

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Hossam woke up bored, so he decided to create an interesting array with his friend Hazem.

Now, they have an array aa of nn positive integers, Hossam will choose a number aia_i and Hazem will choose a number aja_j.

Count the number of interesting pairs (ai,aj)(a_i, a_j) that meet all the following conditions:

  • 1≤i,j≤n1 \le i, j \le n;
  • i≠ji \neq j;
  • The absolute difference ∣ai−aj∣|a_i - a_j| must be equal to the maximum absolute difference over all the pairs in the array. More formally, ∣ai−aj∣=max⁡1≤p,q≤n∣ap−aq∣|a_i - a_j| = \max_{1 \le p, q \le n} |a_p - a_q|.

侯萨姆醒来后感到无聊,于是决定和朋友哈泽姆一起创建一个有趣的数组。

现在,他们有一个由 nn 个正整数组成的数组 aa,侯萨姆将选择一个数 aia_i,哈泽姆将选择一个数 aja_j。

请计算满足以下所有条件的有趣数对 (ai,aj)(a_i, a_j) 的数量:

  • 1≤i,j≤n1 \le i, j \le n;
  • i≠ji \neq j;
  • 绝对差值 ∣ai−aj∣|a_i - a_j| 必须等于该数组中所有数对之间的最大绝对差值。更准确地说,∣ai−aj∣=max⁡1≤p,q≤n∣ap−aq∣|a_i - a_j| = \max_{1 \le p, q \le n} |a_p - a_q|。

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001 \le t \le 100), which denotes the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer nn (2≤n≤1052 \le n \le 10^5).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1051 \le a_i \le 10^5).

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1051 \le a_i \le 10^5)。

保证所有测试用例的 nn 值之和不超过 10510^5。

输出格式

For each test case print an integer — the number of interesting pairs (ai,aj)(a_i, a_j).

对于每个测试用例,输出一个整数——有趣的数对 (ai,aj)(a_i, a_j) 的个数。

输入输出样例

  • 输入#1

    2
    5
    6 2 3 8 1
    6
    7 2 8 3 2 10

    输出#1

    2
    4

说明/提示

In the first example, the two ways are:

  • Hossam chooses the fourth number 88 and Hazem chooses the fifth number 11.
  • Hossam chooses the fifth number 11 and Hazem chooses the fourth number 88.

In the second example, the four ways are:

  • Hossam chooses the second number 22 and Hazem chooses the sixth number 1010.
  • Hossam chooses the sixth number 1010 and Hazem chooses the second number 22.
  • Hossam chooses the fifth number 22 and Hazem chooses the sixth number 1010.
  • Hossam chooses the sixth number 1010 and Hazem chooses the fifth number 22.

在第一个例子中,共有两种方式:

  • 霍萨姆选择第四个数 88,哈泽姆选择第五个数 11。
  • 霍萨姆选择第五个数 11,哈泽姆选择第四个数 88。

在第二个例子中,共有四种方式:

  • 霍萨姆选择第二个数 22,哈泽姆选择第六个数 1010。
  • 霍萨姆选择第六个数 1010,哈泽姆选择第二个数 22。
  • 霍萨姆选择第五个数 22,哈泽姆选择第六个数 1010。
  • 霍萨姆选择第六个数 1010,哈泽姆选择第五个数 22。

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

首页