제출 #1158247

#제출 시각아이디문제언어결과실행 시간메모리
1158247itaykarnyXOR Sum (info1cup17_xorsum)C++20
100 / 100
1399 ms4328 KiB
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int res = 0, k, v;

    for (int i = 30; i >= 0; --i) {
        sort(a.rbegin(), a.rend());
        k = 0;
        for (int j = 0, p = n - 1, q = n - 1, w = n - 1; j < n; ++j) {
            if ((a[j] >> i) & 1) {
                v = (1 << (i + 1)) - a[j] - 1;
                p = max(p, j);
                while (p >= j && a[p] <= v) --p;

                k += (n - 1 - p) & 1;

                v = (3 << i) - a[j];
                q = max(q, j);
                while (q >= j && a[q] < v) --q;
                k += (q - j + 1) & 1;

                a[j] ^= 1 << i;
            }
            else {
                v = (1 << i) - a[j];
                w = max(w, j);
                while (w >= j && a[w] < v) --w;
                k += (w - j + 1) & 1;
            }
        }
        if (k & 1) res |= 1 << i;
    }
    cout << res << '\n';
    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...