1420B.md (1954B)
1 Source: https://codeforces.com/problemset/problem/1420/B 2 3 B. Rock and Lever 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 "You must lift the dam. With a lever. I will give it to you. 22 23 You must block the canal. With a rock. I will not give the rock to you." 24 25 Danik urgently needs rock and lever! Obviously, the easiest way to get these things is to ask Hermit Lizard for them. 26 27 Hermit Lizard agreed to give Danik the lever. But to get a stone, Danik needs to solve the following task. 28 29 You are given a positive integer $n$, and an array $a$ of positive integers. The task is to calculate the number of such pairs $(i,j)$ that $i \lt j$ and $a_i$ $\&$ $a_j \ge a_i \oplus a_j$, where $\&$ denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), and $\oplus$ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). 30 31 Danik has solved this task. But can you solve it? 32 33 Input 34 35 Each test contains multiple test cases. 36 37 The first line contains one positive integer $t$ ($1 \le t \le 10$) denoting the number of test cases. Description of the test cases follows. 38 39 The first line of each test case contains one positive integer $n$ ($1 \le n \le 10^5$) — length of the array. 40 41 The second line contains $n$ positive integers $a_i$ ($1 \le a_i \le 10^9$) — elements of the array. 42 43 It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$. 44 45 Output 46 47 For every test case print one non-negative integer — the answer to the problem. 48 49 Example 50 51 Input 52 53 ``` 54 5 55 5 56 1 4 3 7 10 57 3 58 1 1 1 59 4 60 6 2 5 3 61 2 62 2 4 63 1 64 1 65 ``` 66 67 Output 68 69 ``` 70 1 71 3 72 2 73 0 74 0 75 ``` 76 77 Note 78 79 In the first test case there is only one pair: $(4,7)$: for it $4$ $\&$ $7 = 4$, and $4 \oplus 7 = 3$. 80 81 In the second test case all pairs are good. 82 83 In the third test case there are two pairs: $(6,5)$ and $(2,3)$. 84 85 In the fourth test case there are no good pairs.