最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

CF 1771A - Hossam and Combinatorics

2023-07-05 08:15 作者:您是打尖兒還是住店呢  | 我要投稿

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 ai and Hazem will choose a number aj.

Count the number of interesting pairs (ai,aj) that meet all the following conditions:1≤i,j≤n;i≠j;

The absolute difference |ai?aj| must be equal to the maximum absolute difference over all the pairs in the array. More formally, |ai?aj|=max1≤p,q≤n|ap?aq|.

Input

The input consists of multiple test cases. The first line contains a single integer t (1≤t≤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≤n≤105).


The second line of each test case contains n integers a1,a2,…,an (1≤ai≤105).

It is guaranteed that the sum of n over all test cases does not exceed 105.

Output

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

---------------------------------------------------------------

Hossam 醒來感到很無聊,所以他決定和他的朋友 Hazem 一起創(chuàng)建一個有趣的數(shù)組。

現(xiàn)在,他們有一個由 n 個正整數(shù)組成的數(shù)組 a,Hossam 將選擇一個數(shù)字 ai,Hazem 將選擇一個數(shù)字 aj。

計算滿足以下所有條件的有趣對 (ai,aj) 的數(shù)量:1≤i,j≤n;i≠j;

絕對差|ai?aj| 必須等于數(shù)組中所有對的最大絕對差。 更正式地說,|ai?aj|=max1≤p,q≤n|ap?aq|。

輸入

輸入由多個測試用例組成。 第一行包含一個整數(shù)t(1≤t≤100),表示測試用例的數(shù)量。 測試用例的描述如下。

每個測試用例的第一行包含一個整數(shù)n(2≤n≤105)。


每個測試用例的第二行包含n個整數(shù)a1,a2,…,an

? (1≤ai≤105)。

保證所有測試用例的n之和不超過105。

輸出

對于每個測試用例,打印一個整數(shù) - 有趣的對 (ai,aj) 的數(shù)量。

----------------------------

踩了2個坑,一個是乘積會溢出的情況,沒有看示例的數(shù)據(jù)范圍,一個是沒有考慮極端情況,也就是所有的值全部相當?shù)臅r候。

其他沒什么問題的,下面是代碼:


CF 1771A - Hossam and Combinatorics的評論 (共 條)

分享到微博請遵守國家法律
革吉县| 沙河市| 吉安县| 北安市| 九江县| 云霄县| 福建省| 嘉义市| 长岭县| 三明市| 海安县| 大同市| 出国| 平利县| 山丹县| 横山县| 华坪县| 璧山县| 沾化县| 兰西县| 高雄市| 玉林市| 贵溪市| 永年县| 什邡市| 衢州市| 台湾省| 抚顺市| 芒康县| 柘荣县| 铜陵市| 革吉县| 彭水| 江永县| 平山县| 沂南县| 都兰县| 铅山县| 蒙自县| 克什克腾旗| 新竹县|