답안 #1101053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101053 2024-10-15T12:37:44 Z Kirill22 XOR Sum (info1cup17_xorsum) C++17
100 / 100
765 ms 40868 KB
#include "bits/stdc++.h"

using namespace std;

//#include "debug.h"

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
//    std::sort(a.begin(), a.end(), [&] (int i, int j) { return i % 2 < j % 2; });
    long long ans = 0;
    for (int bit = 0; bit < 31; bit++) {
        long long cnt = 0;
        vector<vector<pair<int, int>>> bucket(2);
//        vector<int> b;
        for (auto& x : a) {
            bucket[x >> bit & 1].push_back({x % (1 << bit), x});
        }
        a.clear();
        for (auto& x : bucket[0]) {
            a.push_back(x.second);
        }
        for (auto& x : bucket[1]) {
            a.push_back(x.second);
        }
//        cout << a.size() << endl;
//        std::sort(bucket[0].begin(), bucket[0].end());
//        std::sort(bucket[1].begin(), bucket[1].end());
        for (auto [_, __] : vector<pair<int, int>>{{0, 0}, {1, 1}}) {
            auto l = bucket[_];
            auto r = bucket[__];
            int uk = 0;
            for (int i = (int) r.size() - 1; i >= 0; i--) {
                while (uk < (int) l.size() && l[uk].first + r[i].first < (1 << bit)) uk++;
                cnt += (int) l.size() - max(uk, i);
            }
        }
//        if (bit == 1) {
//            debug(bucket[0], bucket[1], cnt);
//        }
        for (auto [_, __] : vector<pair<int, int>>{{0, 1}}) {
            auto l = bucket[_];
            auto r = bucket[__];
            int uk = 0;
            for (int i = (int) r.size() - 1; i >= 0; i--) {
                while (uk < (int) l.size() && l[uk].first + r[i].first < (1 << bit)) uk++;
                cnt += uk;
            }
        }
        if (cnt % 2) {
            ans ^= (1 << bit);
        }
    }
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 619 ms 28780 KB Output is correct
2 Correct 545 ms 32116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 619 ms 28780 KB Output is correct
2 Correct 545 ms 32116 KB Output is correct
3 Correct 618 ms 35224 KB Output is correct
4 Correct 624 ms 34056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 90 ms 3464 KB Output is correct
4 Correct 90 ms 3528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 619 ms 28780 KB Output is correct
4 Correct 545 ms 32116 KB Output is correct
5 Correct 618 ms 35224 KB Output is correct
6 Correct 624 ms 34056 KB Output is correct
7 Correct 90 ms 3464 KB Output is correct
8 Correct 90 ms 3528 KB Output is correct
9 Correct 725 ms 39772 KB Output is correct
10 Correct 712 ms 40184 KB Output is correct
11 Correct 765 ms 40868 KB Output is correct