Submission #1354059

#TimeUsernameProblemLanguageResultExecution timeMemory
1354059marcus06XOR Sum (info1cup17_xorsum)C++20
45 / 100
1694 ms8192 KiB
#include <bits/stdc++.h>
using namespace std;
using lli = long long;

void solve() {
    int n; cin >> n;
    vector <int> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];

    vector <int> vv(n);
    lli ans = 0;
    for (int b = 0; b < 30; ++b) {
        for (int i = 0; i < n; ++i) {
            vv[i] = v[i] % (1 << (b + 1));
        }
        sort(vv.begin(), vv.end());

        //must be between 2^(i + 1) and 2^i

        lli cnt = 0;
        int high = 1 << (b + 1), low = 1 << b;
        for (int i = 0; i < n; ++i) {
            int ub = lower_bound(vv.begin() + i, vv.end(), high - vv[i]) - vv.begin();
            int lb = lower_bound(vv.begin() + i, vv.end(), low - vv[i]) - vv.begin();
            cnt += ub - lb;
        }

        high = (1 << (b + 2)), low = (1 << (b + 1)) + (1 << b);
        for (int i = 0; i < n; ++i) {
            int ub = lower_bound(vv.begin() + i, vv.end(), high - vv[i]) - vv.begin();
            int lb = lower_bound(vv.begin() + i, vv.end(), low - vv[i]) - vv.begin();
            cnt += ub - lb;
        }
        if (cnt & 1) ans |= 1 << b;
    }
    cout << ans << '\n';
}

int main() {
    std::cin.tie(0)->sync_with_stdio(0);
#ifdef LOCAL
    auto begin = std::chrono::high_resolution_clock::now();
#endif

    int tt = 1;
    while (tt--) {
        solve();
    }

#ifdef LOCAL
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    std::cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
#endif
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...