Submission #1354084

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

#define BIT(x, i) (((x) >> (i)) & 1)

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

    vector <int> vv, tmp(n);
    auto countAtLeast = [&](int bound) -> lli {
        lli res = 0;
        int l = 0;
        for (int r = n - 1; r >= 0; --r) {
            while (l < r && tmp[l] + tmp[r] < bound) l++;
            if (tmp[l] + tmp[r] >= bound) res += r - l + 1;
        }
        return res;
    };

    vector <lli> cnt(30);
    lli ans = 0;
    for (int b = 0; b < 30; ++b) {
        vv.clear();
        for (int i = 0; i < n; ++i) {
            if (!BIT(v[i], b)) vv.push_back(v[i]);
        }
        for (int i = 0; i < n; ++i) {
            if (BIT(v[i], b)) vv.push_back(v[i]);
        }
        assert((int) vv.size() == n);

        for (int i = 0; i < n; ++i) {
            tmp[i] = vv[i] % (1 << (b + 1));
        }

        int l = 1 << b, r = 1 << (b + 1);
        cnt[b] += countAtLeast(l) - countAtLeast(r);
        if (b + 1 < 30) {
            l = (1 << (b + 1)) + (1 << b);
            r = 1 << (b + 2);
            cnt[b] += countAtLeast(l) - countAtLeast(r);
        }
        swap(v, vv);
    }

    for (int i = 0; i < 30; ++i) {
        if (cnt[i] & 1) ans |= 1 << i;
    }
    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...