Submission #884235

# Submission time Handle Problem Language Result Execution time Memory
884235 2023-12-06T21:37:41 Z aykhn XOR Sum (info1cup17_xorsum) C++17
100 / 100
1132 ms 48896 KB
#include <bits/stdc++.h>
 
// author : aykhn
 
using namespace std;
typedef long long ll;
 
#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcountll
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define int ll
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F

const int MXN = 1e5 + 5;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int a[n];
    pii b[n];
    for (int i = 0; i < n; i++) cin >> a[i], b[i] = mpr(0LL, i);
    int res = 0;
    for (int j = 0; j < 30; j++)
    {
        pii c[n];
        int l = 0;
        int r = n - 1;
        for (int i = n - 1; i >= 0; i--) 
        {
            if (a[b[i].se] >> j & 1) c[r--] = {b[i].fi | (1 << j), b[i].se};
        }
        for (int i = 0; i < n; i++)
        {
            if (!(a[b[i].se] >> j & 1)) c[l++] = b[i];
        }
        for (int i = 0; i < n; i++) b[i] = c[i];
        int cnt = 0;
        int i1, i2, i3, i4;
        i1 = i2 = i3 = i4 = 0;
        for (int i = n - 1; i >= 0; i--)
        {
            while (i1 < n && b[i1].fi < (1 << j) - b[i].fi) i1++;
            while (i2 < n && b[i2].fi < (1 << (j + 1)) - b[i].fi) i2++;
            while (i3 < n && b[i3].fi < ((1 << (j + 1)) | (1 << j)) - b[i].fi) i3++;
            while (i4 < n && b[i4].fi < (1 << (j + 2)) - b[i].fi) i4++;
            if (max(i1, i) < i2) cnt += i2 - max(i1, i);
            if (max(i3, i) < i4) cnt += i4 - max(i3, i);
        }
        if (cnt & 1) res |= (1 << j);
    }
    cout << res << '\n';
}
// ignore (i + 1 -> 23];
// a[i] &= (1 << (i + 1)) - 1;
// (1 << i) <= a[i] + a[j] < (1 << (i + 1));
// (1 << (i + 1)) | (1 << i) <= a[i] + a[j] < (1 << (i + 2))
# Verdict Execution time Memory Grader output
1 Correct 4 ms 604 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 864 ms 39564 KB Output is correct
2 Correct 731 ms 36944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 864 ms 39564 KB Output is correct
2 Correct 731 ms 36944 KB Output is correct
3 Correct 909 ms 39568 KB Output is correct
4 Correct 869 ms 44648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 604 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 84 ms 4344 KB Output is correct
4 Correct 85 ms 4336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 604 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 864 ms 39564 KB Output is correct
4 Correct 731 ms 36944 KB Output is correct
5 Correct 909 ms 39568 KB Output is correct
6 Correct 869 ms 44648 KB Output is correct
7 Correct 84 ms 4344 KB Output is correct
8 Correct 85 ms 4336 KB Output is correct
9 Correct 1108 ms 48780 KB Output is correct
10 Correct 1132 ms 48892 KB Output is correct
11 Correct 1054 ms 48896 KB Output is correct