310006: CF1771A. Hossam and Combinatorics

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Hossam and Combinatorics

题意翻译

给定一个长度为 $n$ 的序列,求满足以下条件的数对 $(i,j)$ 的数量: - $1\le i,j\le n$ - $i\ne j$ - $|a_i-a_j|=\max_{1\le p,q\le n}|a_p-a_q|$

题目描述

Hossam woke up bored, so he decided to create an interesting array with his friend Hazem. Now, they have an array $ a $ of $ n $ positive integers, Hossam will choose a number $ a_i $ and Hazem will choose a number $ a_j $ . Count the number of interesting pairs $ (a_i, a_j) $ that meet all the following conditions: - $ 1 \le i, j \le n $ ; - $ i \neq j $ ; - The absolute difference $ |a_i - a_j| $ must be equal to the maximum absolute difference over all the pairs in the array. More formally, $ |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 $ t $ ( $ 1 \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 $ n $ ( $ 2 \le n \le 10^5 $ ). The second line of each test case contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \le a_i \le 10^5 $ ). It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^5 $ .

输出格式


For each test case print an integer — the number of interesting pairs $ (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 $ 8 $ and Hazem chooses the fifth number $ 1 $ . - Hossam chooses the fifth number $ 1 $ and Hazem chooses the fourth number $ 8 $ . In the second example, the four ways are: - Hossam chooses the second number $ 2 $ and Hazem chooses the sixth number $ 10 $ . - Hossam chooses the sixth number $ 10 $ and Hazem chooses the second number $ 2 $ . - Hossam chooses the fifth number $ 2 $ and Hazem chooses the sixth number $ 10 $ . - Hossam chooses the sixth number $ 10 $ and Hazem chooses the fifth number $ 2 $ .

Input

题意翻译

给定一个长度为 $n$ 的序列,求满足以下条件的数对 $(i,j)$ 的数量: - $1\le i,j\le n$ - $i\ne j$ - $|a_i-a_j|=\max_{1\le p,q\le n}|a_p-a_q|$

Output

**题意翻译**

给定一个长度为 $ n $ 的序列,求满足以下条件的数对 $ (i,j) $ 的数量:

- $ 1 \le i,j \le n $
- $ i \ne j $
- $ |a_i-a_j| = \max_{1 \le p,q \le n} |a_p-a_q| $

**题目描述**

Hossam 和他的朋友 Hazem 有一个包含 $ n $ 个正整数的数组 $ a $。Hossam 选择一个数 $ a_i $,Hazem 选择一个数 $ a_j $。计算满足以下条件的“有趣”数对 $ (a_i, a_j) $ 的数量:

- $ 1 \le i, j \le n $;
- $ i \neq j $;
- 绝对差 $ |a_i - a_j| $ 必须等于数组中所有数对的最大绝对差。更正式地说,$ |a_i - a_j| = \max_{1 \le p, q \le n} |a_p - a_q| $。

**输入输出格式**

**输入格式**

输入包含多个测试用例。第一行包含一个整数 $ t $($ 1 \le t \le 100 $),表示测试用例的数量。接下来是每个测试用例的描述。

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

每个测试用例的第二行包含 $ n $ 个整数 $ a_1, a_2, \dots, a_n $($ 1 \le a_i \le 10^5 $)。

保证所有测试用例的 $ n $ 之和不超过 $ 10^5 $。

**输出格式**

对于每个测试用例,输出一个整数,表示“有趣”数对 $ (a_i, a_j) $ 的数量。

**输入输出样例**

**输入样例 #1**

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

**输出样例 #1**

```
2
4
```

**说明**

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

- Hossam 选择第四个数 $ 8 $,Hazem 选择第五个数 $ 1 $。
- Hossam 选择第五个数 $ 1 $,Hazem 选择第四个数 $ 8 $。

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

- Hossam 选择第二个数 $ 2 $,Hazem 选择第六个数 $ 10 $。
- Hossam 选择第六个数 $ 10 $,Hazem 选择第二个数 $ 2 $。
- Hossam 选择第五个数 $ 2 $,Hazem 选择第六个数 $ 10 $。
- Hossam 选择第六个数 $ 10 $,Hazem 选择第五个数 $ 2 $。**题意翻译** 给定一个长度为 $ n $ 的序列,求满足以下条件的数对 $ (i,j) $ 的数量: - $ 1 \le i,j \le n $ - $ i \ne j $ - $ |a_i-a_j| = \max_{1 \le p,q \le n} |a_p-a_q| $ **题目描述** Hossam 和他的朋友 Hazem 有一个包含 $ n $ 个正整数的数组 $ a $。Hossam 选择一个数 $ a_i $,Hazem 选择一个数 $ a_j $。计算满足以下条件的“有趣”数对 $ (a_i, a_j) $ 的数量: - $ 1 \le i, j \le n $; - $ i \neq j $; - 绝对差 $ |a_i - a_j| $ 必须等于数组中所有数对的最大绝对差。更正式地说,$ |a_i - a_j| = \max_{1 \le p, q \le n} |a_p - a_q| $。 **输入输出格式** **输入格式** 输入包含多个测试用例。第一行包含一个整数 $ t $($ 1 \le t \le 100 $),表示测试用例的数量。接下来是每个测试用例的描述。 每个测试用例的第一行包含一个整数 $ n $($ 2 \le n \le 10^5 $)。 每个测试用例的第二行包含 $ n $ 个整数 $ a_1, a_2, \dots, a_n $($ 1 \le a_i \le 10^5 $)。 保证所有测试用例的 $ n $ 之和不超过 $ 10^5 $。 **输出格式** 对于每个测试用例,输出一个整数,表示“有趣”数对 $ (a_i, a_j) $ 的数量。 **输入输出样例** **输入样例 #1** ``` 2 5 6 2 3 8 1 6 7 2 8 3 2 10 ``` **输出样例 #1** ``` 2 4 ``` **说明** 在第一个例子中,有两种方式: - Hossam 选择第四个数 $ 8 $,Hazem 选择第五个数 $ 1 $。 - Hossam 选择第五个数 $ 1 $,Hazem 选择第四个数 $ 8 $。 在第二个例子中,有四种方式: - Hossam 选择第二个数 $ 2 $,Hazem 选择第六个数 $ 10 $。 - Hossam 选择第六个数 $ 10 $,Hazem 选择第二个数 $ 2 $。 - Hossam 选择第五个数 $ 2 $,Hazem 选择第六个数 $ 10 $。 - Hossam 选择第六个数 $ 10 $,Hazem 选择第五个数 $ 2 $。

加入题单

算法标签: