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

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
兰西县| 黄大仙区| 渭源县| 荆州市| 松桃| 珲春市| 鸡西市| 大安市| 赫章县| 沈阳市| 连江县| 寿阳县| 宁陕县| 桃源县| 溆浦县| 桐乡市| 宁晋县| 买车| 广安市| 上犹县| 故城县| 九龙县| 文登市| 汽车| 屏山县| 塔城市| 郯城县| 玉屏| 余干县| 深泽县| 修武县| 新巴尔虎左旗| 枣阳市| 东乌| 铜山县| 乐平市| 西畴县| 武汉市| 三穗县| 汽车| 含山县|