Submission #1148307

#TimeUsernameProblemLanguageResultExecution timeMemory
1148307weakweakweakXOR Sum (info1cup17_xorsum)C++20
56 / 100
1696 ms123952 KiB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

int n, a[1888888], B = 30;
vector<int> v[31];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    // if (n > 100000) B = 12;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    int ans = 0;
    for (int b = 0; b < B; b++) {
        int z = (1<<(b+1))-1;
        for (int i = 1; i <= n; i++) v[b].push_back(z&a[i]);
        sort(v[b].begin(), v[b].end());
        long long cnt = 0;
        int th1 = (1<<b), th2 = (1<<(b+1)), th3 = th1+th2;
        for (int i = 0, j=n, j2=n, j3=n; i < n; i++) {
            while (j3 > 0 and v[b][i] + v[b][j3-1] >= th3) j3--;
            if (j2 > j3) j2 = j3;
            while (j2 > 0 and v[b][i] + v[b][j2-1] >= th2) j2--;
            if (j > j2) j = j2;
            while (j > 0 and v[b][i] + v[b][j-1] >= th1) j--;
            int a1 = n - j, a2 = n - j2, a3 = n - j3;
            cnt += (a1-a2);
            cnt += (a3);
        }
        for (int i = 1; i <= n; i++) if ((a[i]+a[i])&(1<<b)) cnt++;
        cnt /= 2;
        if (cnt & 1) ans += (1<<b);
    }
    cout << ans << '\n';
}
#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...