답안 #389452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389452 2021-04-14T06:10:06 Z cheissmart XOR Sum (info1cup17_xorsum) C++14
100 / 100
1312 ms 28700 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;

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;
    V<pi> aux(n);
    for(int i = 0; i < n; i++) aux[i].S = a[i];
    for(int bit = 0; bit < 30; bit++) {
        ll cnt = 0;
        for(int i = 0; i < n; i++) {
            aux[i].F = aux[i].S & ((1 << (bit + 1)) - 1);
            if((aux[i].F * 2) >> bit & 1) cnt++;
        }
        V<pi> saux;
        for(int i = 0; i < n; i++) if(((aux[i].F >> bit) & 1) == 0) saux.PB(aux[i]);
        for(int i = 0; i < n; i++) if((aux[i].F >> bit) & 1) saux.PB(aux[i]);
        aux = saux;
        //sort(ALL(aux));
        for(int i = 0, j = n, k = n; i < n; i++) {
            auto go = [&] (ll lb, ll rb) {
                lb -= aux[i].F, rb -= aux[i].F;
                while(j - 1 >= 0 && aux[j - 1].F >= lb) j--;
                while(k - 1 >= 0 && aux[k - 1].F > rb) k--;
                cnt += k - j;
            };
            go(1 << bit, (1 << (bit + 1)) - 1);
        }
        for(int i = 0, j = n, k = n; i < n; i++) {
            auto go = [&] (ll lb, ll rb) {
                lb -= aux[i].F, rb -= aux[i].F;
                while(j - 1 >= 0 && aux[j - 1].F >= lb) j--;
                while(k - 1 >= 0 && aux[k - 1].F > rb) k--;
                cnt += k - j;
            };
            go(3 << bit, (2LL << (bit + 1)) - 1);
        }
        //debug(cnt);
        assert(cnt % 2 == 0);
        cnt /= 2;
        if(cnt & 1) ans |= 1 << bit;
    }
    cout << ans << '\n';

}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 332 KB Output is correct
2 Correct 5 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 893 ms 28156 KB Output is correct
2 Correct 794 ms 27208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 893 ms 28156 KB Output is correct
2 Correct 794 ms 27208 KB Output is correct
3 Correct 1004 ms 28700 KB Output is correct
4 Correct 970 ms 27996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 332 KB Output is correct
2 Correct 5 ms 332 KB Output is correct
3 Correct 133 ms 3368 KB Output is correct
4 Correct 131 ms 3340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 332 KB Output is correct
2 Correct 5 ms 332 KB Output is correct
3 Correct 893 ms 28156 KB Output is correct
4 Correct 794 ms 27208 KB Output is correct
5 Correct 1004 ms 28700 KB Output is correct
6 Correct 970 ms 27996 KB Output is correct
7 Correct 133 ms 3368 KB Output is correct
8 Correct 131 ms 3340 KB Output is correct
9 Correct 1296 ms 28636 KB Output is correct
10 Correct 1312 ms 28564 KB Output is correct
11 Correct 1272 ms 28676 KB Output is correct