Submission #999525

# Submission time Handle Problem Language Result Execution time Memory
999525 2024-06-15T17:09:56 Z LOLOLO XOR Sum (info1cup17_xorsum) C++17
100 / 100
618 ms 29356 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 1e6 + 10;
int a[N], n, v[N], nxt[N], tmp[N], id[N];

ll cal(int t) {
    ll ans = 0;
    int p = n;

    for (int i = 1; i <= n; i++) {
        while (p - 1 >= 1 && v[i] + v[p - 1] >= t)
            p--;

        if (v[i] + v[p] >= t)
            ans += max(0, i - p + 1);
    }

    return ans;
}

int is(int j) {
    ll t = cal((1 << (j + 1)) | ((1 << j))) + cal((1 << (j + 1))) - cal(1 << j);
    return t % 2;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        id[i] = i;
    }

    int ans = 0, all = 0;
    for (int j = 0; j < 30; j++) {
        int x = 0, y = 0;
        all |= (1 << j);
        for (int i = 1; i <= n; i++) {
            if (a[id[i]] & (1 << j)) {
                nxt[++x] = id[i];
            } else {
                tmp[++y] = id[i]; 
            }
        }

        for (int i = 1; i <= y; i++) {
            v[i] = a[tmp[i]] & all;
            id[i] = tmp[i];
        }

        for (int i = y + 1; i <= n; i++) {
            v[i] = a[nxt[i - y]] & all;
            id[i] = nxt[i - y];
        }

        if (is(j))
            ans |= (1 << j);
    }

    cout << ans << '\n';
    return 0;
}
/*
011
011
*/
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 4 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 350 ms 19796 KB Output is correct
2 Correct 311 ms 19540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 350 ms 19796 KB Output is correct
2 Correct 311 ms 19540 KB Output is correct
3 Correct 432 ms 20008 KB Output is correct
4 Correct 415 ms 26196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 4 ms 8540 KB Output is correct
3 Correct 65 ms 12880 KB Output is correct
4 Correct 67 ms 12684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 4 ms 8540 KB Output is correct
3 Correct 350 ms 19796 KB Output is correct
4 Correct 311 ms 19540 KB Output is correct
5 Correct 432 ms 20008 KB Output is correct
6 Correct 415 ms 26196 KB Output is correct
7 Correct 65 ms 12880 KB Output is correct
8 Correct 67 ms 12684 KB Output is correct
9 Correct 618 ms 29184 KB Output is correct
10 Correct 618 ms 29176 KB Output is correct
11 Correct 609 ms 29356 KB Output is correct