Submission #373503

# Submission time Handle Problem Language Result Execution time Memory
373503 2021-03-04T22:36:41 Z qpwoeirut XOR Sum (info1cup17_xorsum) C++17
0 / 100
784 ms 131072 KB
//xorsum.cpp created at 03/04/21 10:30:22

#include <bits/stdc++.h>

using namespace std;

const int MN = 1000006;
const int LG = 24;

int N;
int A[MN];
int psum[1 << (LG + 2)];

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> N;
    for (int i=0; i<N; ++i) {
        cin >> A[i];
    }

    int ans = 0;
    for (int i=0; i<LG; ++i) {
        fill(psum, psum + (1 << LG) + 1, 0);
        for (int j=0; j<N; ++j) {
            ++psum[(A[j] & ((1 << (i + 1)) - 1)) + 1]; // add 1 for easy indexing stuff
        }
        for (int j=1; j<=(1 << (i+2)); ++j) {
            psum[j] += psum[j - 1];
        }

        // range [2^i, 2^(i+1)) and [2^(i+1) + 2^i, 2^(i+2))
        int ct = 0;
        for (int j=0; j<N; ++j) {
            const int val = A[j] & ((1 << (i + 1)) - 1);
            const int lo1 = (1 << i) - val;
            ct += psum[(1 << (i + 1)) - val] - psum[lo1 < 0 ? 0 : lo1];

            const int lo2 = min(1 << (i+2), (1 << (i + 1)) + lo1);
            const int hi2 = min(1 << (i+2), (1 << (i + 2)) - val);
            ct += psum[hi2] - psum[lo2];

            ct += ((A[j] << 1) >> i) & 1;
        }

        assert((ct & 1) == 0);
        ct = (ct >> 1) & 1;
        ans += ct << i;
    }

    for (int i=LG; i<=30; ++i) {
        
    }

    cout << ans << '\n';
}

/*
4  
3 9 6 6 

00110   1 1
01100   1 2
01001   1 3
01001   1 4
10010   2 2
01111   2 3
01111   2 4
01100   3 3
01100   3 4
01100   4 4
*/
# Verdict Execution time Memory Grader output
1 Runtime error 508 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 784 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 784 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 508 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 508 ms 131072 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -