-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXometry (Easy Version)
57 lines (49 loc) Β· 1.29 KB
/
Xometry (Easy Version)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
class XORPairCounter {
private:
static constexpr int MAX_XOR = 1 << 20;
std::array<int64_t, MAX_XOR> xor_counts;
std::vector<int> numbers;
void countXORPairs() {
xor_counts.fill(0);
for (size_t i = 0; i < numbers.size(); ++i) {
for (size_t j = i + 1; j < numbers.size(); ++j) {
++xor_counts[numbers[j] ^ numbers[i]];
}
}
}
int64_t calculateTotalPairs() const {
return std::accumulate(xor_counts.begin(), xor_counts.end(), int64_t(0),
[](int64_t sum, int64_t count) { return sum + count * (count - 1); });
}
public:
void readInput() {
int n;
std::cin >> n;
numbers.resize(n);
std::for_each(numbers.begin(), numbers.end(), [](int& num) { std::cin >> num; });
}
int64_t solve() {
countXORPairs();
return calculateTotalPairs() * 4;
}
};
void solveTestCase() {
XORPairCounter counter;
counter.readInput();
std::cout << counter.solve() << std::endl;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T--) {
solveTestCase();
}
return 0;
}