답안 #97179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97179 2019-02-14T09:37:59 Z popovicirobert XOR Sum (info1cup17_xorsum) C++14
100 / 100
1431 ms 20028 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAXN = (int) 1e6;

int arr[MAXN + 1];
pair <int, int> nrm[MAXN + 1], aux[MAXN + 1];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    int l = 1, r = n;
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
        if(arr[i] & 1) {
            nrm[r--] = {1, i};
        }
        else {
            nrm[l++] = {0, i};
        }
    }
    int ans = 0;
    for(int bit = 0; bit <= 29; bit++) {
        ll cur = 0;
        int l0 = n, r0 = n;
        int l1 = n, r1 = n;
        for(i = 1; i <= n; i++) {
            while(l0 >= 1 && nrm[i].first + nrm[l0].first >= (1 << bit)) {
                l0--;
            }
            while(r0 >= 1 && nrm[i].first + nrm[r0].first >= (1 << (bit + 1))) {
                r0--;
            }
            while(l1 >= 1 && nrm[i].first + nrm[l1].first >= (1 << (bit + 1)) + (1 << bit)) {
                l1--;
            }
            while(r1 >= 1 && nrm[i].first + nrm[r1].first >= (1 << (bit + 2))) {
                r1--;
            }
            cur += r1 - l1 + r0 - l0;
            cur += (((2 * nrm[i].first) & (1 << bit)) > 0);
        }
        cur /= 2, cur &= 1;
        ans += cur * (1 << bit);
        int sz = 0;
        for(i = 1; i <= n; i++) {
            int cur = nrm[i].second;
            if((arr[cur] & (1 << (bit + 1))) == 0) {
                aux[++sz] = {arr[cur] & ((1 << (bit + 2)) - 1), cur};
            }
        }
        for(i = 1; i <= n; i++) {
            int cur = nrm[i].second;
            if(arr[cur] & (1 << (bit + 1))) {
                aux[++sz] = {arr[cur] & ((1 << (bit + 2)) - 1), cur};
            }
        }
        for(i = 1; i <= n; i++) {
            nrm[i] = aux[i];
        }
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 8 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1109 ms 19960 KB Output is correct
2 Correct 1047 ms 18660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1109 ms 19960 KB Output is correct
2 Correct 1047 ms 18660 KB Output is correct
3 Correct 1197 ms 20016 KB Output is correct
4 Correct 1377 ms 19260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 8 ms 256 KB Output is correct
3 Correct 122 ms 2372 KB Output is correct
4 Correct 104 ms 2240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 8 ms 256 KB Output is correct
3 Correct 1109 ms 19960 KB Output is correct
4 Correct 1047 ms 18660 KB Output is correct
5 Correct 1197 ms 20016 KB Output is correct
6 Correct 1377 ms 19260 KB Output is correct
7 Correct 122 ms 2372 KB Output is correct
8 Correct 104 ms 2240 KB Output is correct
9 Correct 1431 ms 19948 KB Output is correct
10 Correct 1320 ms 20028 KB Output is correct
11 Correct 1385 ms 19952 KB Output is correct