답안 #1110788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110788 2024-11-10T13:30:39 Z _callmelucian XOR Sum (info1cup17_xorsum) C++14
100 / 100
657 ms 31060 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;
    vector<int> a(n), ord(n);

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        ord[i] = i;
    }

    int ans = 0;
    for (int bit = 0; bit < 31; bit++) {
        // sort
        vector<int> zeroBit, oneBit, vec(n);
        for (int u : ord) {
            if ((a[u] >> bit) & 1) oneBit.push_back(u);
            else zeroBit.push_back(u);
        }
        ord = zeroBit, ord.insert(ord.end(), all(oneBit));

        // last (`bit` + 1) bits
        for (int i = 0; i < n; i++)
            vec[i] = a[ord[i]] & ((1 << (bit + 1)) - 1);

        // calculate
        int zero = -1, one = -1, two = -1;
        for (int i = (int)ord.size() - 1; i >= 0; i--) {
            zero = min(zero, i), one = min(one, i), two = min(two, i);
            while (zero + 1 <= i && ((vec[zero + 1] + vec[i]) >> bit) <= 0) zero++;
            while (one + 1 <= i && ((vec[one + 1] + vec[i]) >> bit) <= 1) one++;
            while (two + 1 <= i && ((vec[two + 1] + vec[i]) >> bit) <= 2) two++;
            int cntOne = one - zero + i - two;
            if (cntOne & 1) ans ^= (1 << bit);
        }
    }
    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 21928 KB Output is correct
2 Correct 468 ms 23556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 21928 KB Output is correct
2 Correct 468 ms 23556 KB Output is correct
3 Correct 554 ms 28464 KB Output is correct
4 Correct 506 ms 27752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 59 ms 2552 KB Output is correct
4 Correct 66 ms 2556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 459 ms 21928 KB Output is correct
4 Correct 468 ms 23556 KB Output is correct
5 Correct 554 ms 28464 KB Output is correct
6 Correct 506 ms 27752 KB Output is correct
7 Correct 59 ms 2552 KB Output is correct
8 Correct 66 ms 2556 KB Output is correct
9 Correct 630 ms 30884 KB Output is correct
10 Correct 653 ms 30952 KB Output is correct
11 Correct 657 ms 31060 KB Output is correct