QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698142#8077. Alice and BobxizhaoRE 0ms0kbC++201.5kb2024-11-01 17:40:292024-11-01 17:40:30

Judging History

你现在查看的是最新测评结果

  • [2024-11-01 17:40:30]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-01 17:40:29]
  • 提交

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

output:


result: