답안 #389280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389280 2021-04-14T02:11:24 Z syl123456 XOR Sum (info1cup17_xorsum) C++17
77 / 100
1600 ms 91948 KB
#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
template<typename T1, typename T2>
ostream& operator << (ostream &i, pair<T1, T2> j) {
    return i << j.first << ' ' << j.second;
}
template<typename T>
ostream& operator << (ostream &i, vector<T> j) {
    i << '{' << j.size() << ':';
    for (T ii : j) i << ' ' << ii;
    return i << '}';
}
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<pi, int> pp;
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    int a[n], _mx = 0;
    for (int &i : a) cin >> i, _mx = max(_mx, i);
    int ans = 0;
    for (int i = 0; i < 21; ++i) {
        int x = (1 << i + 1) - 1, cnt[x + 1]{};
        ll tmp = 0;
        for (int j : a) ++cnt[j & x];
        for (int j = 1; j < 1 << i; ++j) cnt[j] += cnt[j - 1];
        for (int j = (1 << i) + 1; j < 1 << i + 1; ++j) cnt[j] += cnt[j - 1];
        for (int j : a) {
            j &= x;
            if (j << 1 & 1 << i) ++tmp;
            if (j >> i & 1) {
                tmp += cnt[x - j];
                tmp += cnt[x] - cnt[x + (1 << i) - j];
            }
            else {
                tmp += cnt[x >> 1] - cnt[(x >> 1) - j];
                tmp += cnt[x - j];
            }
        }
        if (tmp & 2) ans ^= 1 << i;
    }
    if (_mx <= 1e6) return cout << ans, 0;
    for (int i = 21; i < 30; ++i) {
        int x = (1 << i + 1) - 1;
        map<int, int> cnt, pre;
        ll tmp = 0;
        for (int j : a) ++cnt[j & x];
        int s = 0;
        bool b = false;
        for (pi j : cnt) {
            if (!b && j.first >> i & 1) b = true, s = 0;
            s += j.second, pre[j.first] = s;
        }
        auto calc = [&](int j) {
            auto it = pre.lower_bound(j + 1);
            if (it == pre.begin()) return 0;
            --it;
            if (j >> i & 1 && ~(it->first) >> i & 1) return 0;
            return it->second;
        };
        for (int j : a) {
            j &= x;
            if (j << 1 & 1 << i) ++tmp;
            if (j >> i & 1) {
                tmp += calc(x - j);
                tmp += calc(x) - calc(x + (1 << i) - j);
            }
            else {
                tmp += calc(x >> 1) - calc((x >> 1) - j);
                tmp += calc(x - j);
            }
        }
        if (tmp & 2) ans ^= 1 << i;
    }
    cout << ans;
}
/*
 *
 *
 *
 *
 */

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:26:25: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   26 |         int x = (1 << i + 1) - 1, cnt[x + 1]{};
      |                       ~~^~~
xorsum.cpp:30:47: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   30 |         for (int j = (1 << i) + 1; j < 1 << i + 1; ++j) cnt[j] += cnt[j - 1];
      |                                             ~~^~~
xorsum.cpp:47:25: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   47 |         int x = (1 << i + 1) - 1;
      |                       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8820 KB Output is correct
2 Correct 40 ms 8912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 274 ms 12396 KB Output is correct
2 Correct 253 ms 12132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 274 ms 12396 KB Output is correct
2 Correct 253 ms 12132 KB Output is correct
3 Correct 345 ms 12632 KB Output is correct
4 Correct 330 ms 12232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8820 KB Output is correct
2 Correct 40 ms 8912 KB Output is correct
3 Correct 1182 ms 18416 KB Output is correct
4 Correct 1174 ms 18448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8820 KB Output is correct
2 Correct 40 ms 8912 KB Output is correct
3 Correct 274 ms 12396 KB Output is correct
4 Correct 253 ms 12132 KB Output is correct
5 Correct 345 ms 12632 KB Output is correct
6 Correct 330 ms 12232 KB Output is correct
7 Correct 1182 ms 18416 KB Output is correct
8 Correct 1174 ms 18448 KB Output is correct
9 Execution timed out 1693 ms 91948 KB Time limit exceeded
10 Halted 0 ms 0 KB -