CF1899D.Yarik and Musical Notes
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Yarik is a big fan of many kinds of music. But Yarik loves not only listening to music but also writing it. He likes electronic music most of all, so he has created his own system of music notes, which, in his opinion, is best for it.
Since Yarik also likes informatics, in his system notes are denoted by integers of 2k, where k≥1 — a positive integer. But, as you know, you can't use just notes to write music, so Yarik uses combinations of two notes. The combination of two notes (a,b), where a=2k and b=2l, he denotes by the integer ab.
For example, if a=8=23, b=4=22, then the combination (a,b) is denoted by the integer ab=84=4096. Note that different combinations can have the same notation, e.g., the combination (64,2) is also denoted by the integer 4096=642.
Yarik has already chosen n notes that he wants to use in his new melody. However, since their integers can be very large, he has written them down as an array a of length n, then the note i is bi=2ai. The integers in array a can be repeated.
The melody will consist of several combinations of two notes. Yarik was wondering how many pairs of notes bi,bj (i<j) exist such that the combination (bi,bj) is equal to the combination (bj,bi). In other words, he wants to count the number of pairs (i,j) (i<j) such that bibj=bjbi. Help him find the number of such pairs.
亚里克是多种音乐的忠实粉丝。但亚里克不仅喜欢听音乐,还喜欢创作音乐。他尤其钟爱电子音乐,因此设计了一套自认为最适合电子音乐的音符系统。
由于亚里克也热爱信息学,在他的系统中,音符用形如 2k 的整数表示,其中 k≥1 为正整数。然而,众所周知,仅靠单个音符无法谱写音乐,因此亚里克使用两个音符的组合。对于两个音符 (a,b)(其中 a=2k、b=2l),他用整数 ab 表示该组合。
例如,若 a=8=23、b=4=22,则组合 (a,b) 表示为整数 ab=84=4096。注意,不同组合可能具有相同的表示,例如组合 (64,2) 同样表示为整数 4096=642。
亚里克已选定 n 个将在新旋律中使用的音符。但由于这些音符对应的整数可能极大,他将它们记录为一个长度为 n 的数组 a,其中第 i 个音符为 bi=2ai。数组 a 中的整数可以重复。
该旋律将由若干对音符组合构成。亚里克好奇:在所有满足 i<j 的音符对 (bi,bj) 中,有多少对满足组合 (bi,bj) 等于组合 (bj,bi)?换言之,他希望统计满足 bibj=bjbi 的下标对 (i,j)(其中 i<j)的数量。请帮助他求出这样的对数。
输入格式
The first line of the input contains one integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains one integer n (1≤n≤2⋅105) — the length of the arrays.
The next line contains n integers a1,a2,…,an (1≤ai≤109) — array a.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
输入的第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 表示数组的长度。
接下来的一行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 即数组 a。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, output the number of pairs that satisfy the given condition.
对于每个测试用例,输出满足给定条件的数对个数。
输入输出样例
输入#1
5 1 2 4 3 1 3 2 2 1000 1000 3 1 1 1 19 2 4 1 6 2 8 5 4 2 10 5 10 8 7 4 3 2 6 10
输出#1
0 2 1 3 19
输入解题思路,AI测评打分。不知道怎么写?