Submission #389416

# Submission time Handle Problem Language Result Execution time Memory
389416 2021-04-14T04:03:47 Z cheissmart XOR Sum (info1cup17_xorsum) C++14
0 / 100
143 ms 131076 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "LINE(" << __LINE__ << "): " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 5e5 + 1;

struct trie {
    int t[N * 30][2], sz[N * 30];
    int hb, cnt;
    trie(int _hb) {
        hb = _hb;
        memset(t, 0, sizeof t);
        memset(sz, 0, sizeof sz);
        cnt = 0;
    }
    void add(int x) {
        int u = 0;
        for(int i = hb; i >= 0; i--) {
            int c = x >> i & 1;
            if(t[u][c] == 0) t[u][c] = ++cnt;
            u = t[u][c];
            sz[u]++;
        }
    }
    int carry(int u, int x, int bit) {
        if(u == 0 || bit < 0) return 0;
        int ans = 0;
        if(x >> bit & 1) {
            ans += sz[t[u][1]];
            ans += carry(t[u][0], x, bit - 1);
        } else {
            ans += carry(t[u][1], x, bit - 1);
        }
        return ans;
    }
    int qry(int x) {
        int c = x >> hb & 1;
        int ans = 0;
        for(int i = 0; i < 2; i++) {
            if(t[0][i] == 0) continue;
            int res = c ^ i;
            if(res == 0) ans += carry(t[0][i], x, hb - 1);
            else ans += sz[t[0][i]] - carry(t[0][i], x, hb - 1);
        }
        return ans;
    }
};

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

    mt19937 rng(time(0));
    int n;
    cin >> n;
    //n = 10;
    vi a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        //a[i] = rng() % 100;
    }

    /*int myans = 0;
    for(int i = 0; i < n; i++)
        for(int j = i; j < n; j++)
            myans ^= a[i] + a[j];
    debug(myans);
    */
    int ans = 0;
    for(int bit = 0; bit < 30; bit++) {
        ll odd_cnt = 0;
        trie t(bit);
        for(int i = 0; i < n; i++) {
            t.add(a[i]);
            odd_cnt += t.qry(a[i]);
        }
        //debug(odd_cnt);
        if(odd_cnt & 1) ans |= 1 << bit;
    }
    cout << ans << '\n';

}
# Verdict Execution time Memory Grader output
1 Runtime error 62 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 143 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 143 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 62 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 62 ms 131076 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -