QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698142 | #8077. Alice and Bob | xizhao | RE | 0ms | 0kb | C++20 | 1.5kb | 2024-11-01 17:40:29 | 2024-11-01 17:40:30 |
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
#define x first
#define y second
constexpr int N = 4e7;
i64 C(int a, int b) {
if (b > a) return 0;
i64 ans = 1;
for (int i = 0; i < b; i++) ans *= (a - i);
for (int i = 1; i <= b; i++) ans /= i;
return ans;
}
int trie[N][2], idx;
int cnt[N];
i64 insert(i64 x, int sz) {
int p = 0;
for (int i = 0; i < 63; i++) {
int c = x >> i & 1;
if (!trie[p][c]) trie[p][c] = ++idx;
p = trie[p][c];
cnt[p] += sz;
}
}
i64 query(i64 x, int sz) {
int p = 0;
i64 ans = 0;
for (int i = 0; i < 63; i++) {
int c = x >> i & 1;
if (trie[p][c ^ 1]) {
if (!(i & 1)) {
ans += C(sz, 2) * cnt[trie[p][c ^ 1]];
}
}
p = trie[p][c];
}
return ans;
}
void solve() {
int n;
cin >> n;
unordered_map<i64, int> mp;
for (int i = 0; i < n; i++) {
i64 x;
cin >> x;
mp[x]++;
}
i64 ans = 0;
for (auto [x, c] : mp) {
ans += C(c, 3);
insert(x, c);
}
for (auto [x, c] : mp) {
ans += query(x, c);
}
cout << C(n, 3) - ans << '\n';
for (int i = 0; i <= idx; i++) {
trie[i][0] = trie[i][1] = 0;
cnt[i] = 0;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 4 2 0 2 3 3 2 2 3 3 0 2 3