Submission #389254

# Submission time Handle Problem Language Result Execution time Memory
389254 2021-04-14T01:42:57 Z abc864197532 XOR Sum (info1cup17_xorsum) C++17
56 / 100
1600 ms 10864 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define test(x) cout << #x << ' ' << x << endl
#define printv(x) { \
    for (auto a : x) cout << a << ' '; \
    cout << endl; \
}
#define pii pair<int, int>
#define pll pair<lli, lli>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int N = 200000, abc = 864197532;

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    int ans = 0, mx = *max_element(all(a));
    for (int k = __lg(mx) + 1; ~k; --k) {
        for (int i = 0; i < n; ++i) if (a[i] >= (1 << k + 1)) a[i] -= (1 << k + 1);
        sort(all(a));
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            int r = lower_bound(all(a), (1 << k + 1) - a[i]) - a.begin() - i;
            int l = lower_bound(all(a), (1 << k) - a[i]) - a.begin() - i;
            r = max(r, 0), l = max(l, 0);
            cnt ^= (r - l) & 1;
            r = n - i;
            l = lower_bound(all(a), 3 * (1 << k) - a[i]) - a.begin() - i;
            l = max(l, 0);
            cnt ^= (r - l) & 1;
        }
        /*
         * check k bit
         * mod 2^{k + 1}
         * 1 3
         * count pair 2^k <= a + b < 2^{k + 1}
         * 3 * 2^k - a > b
         */
        if (cnt) ans |= 1 << k;
    }
    cout << ans << endl;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:29:57: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   29 |         for (int i = 0; i < n; ++i) if (a[i] >= (1 << k + 1)) a[i] -= (1 << k + 1);
      |                                                       ~~^~~
xorsum.cpp:29:79: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   29 |         for (int i = 0; i < n; ++i) if (a[i] >= (1 << k + 1)) a[i] -= (1 << k + 1);
      |                                                                             ~~^~~
xorsum.cpp:33:49: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   33 |             int r = lower_bound(all(a), (1 << k + 1) - a[i]) - a.begin() - i;
      |                                               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 336 KB Output is correct
2 Correct 16 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1430 ms 4216 KB Output is correct
2 Correct 1324 ms 3960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1430 ms 4216 KB Output is correct
2 Correct 1324 ms 3960 KB Output is correct
3 Execution timed out 1699 ms 10864 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 336 KB Output is correct
2 Correct 16 ms 332 KB Output is correct
3 Correct 435 ms 716 KB Output is correct
4 Correct 433 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 336 KB Output is correct
2 Correct 16 ms 332 KB Output is correct
3 Correct 1430 ms 4216 KB Output is correct
4 Correct 1324 ms 3960 KB Output is correct
5 Execution timed out 1699 ms 10864 KB Time limit exceeded
6 Halted 0 ms 0 KB -