답안 #389419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389419 2021-04-14T04:06:14 Z cheissmart XOR Sum (info1cup17_xorsum) C++14
45 / 100
1600 ms 40912 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 = 1e6 + 1;

struct trie {
    //int t[N * 30][2], sz[N * 30];
    V<array<int, 3>> t;
    vi sz;
    int hb, cnt;
    trie(int _hb) {
        hb = _hb;
        cnt = 0;
        t.PB({0, 0});
        sz.PB(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, t.PB({0, 0}), sz.PB(0);
            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';

}
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 2752 KB Output is correct
2 Correct 45 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1683 ms 4416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1683 ms 4416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 2752 KB Output is correct
2 Correct 45 ms 2680 KB Output is correct
3 Correct 1472 ms 40884 KB Output is correct
4 Correct 1520 ms 40912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 2752 KB Output is correct
2 Correct 45 ms 2680 KB Output is correct
3 Execution timed out 1683 ms 4416 KB Time limit exceeded
4 Halted 0 ms 0 KB -