Submission #440601

# Submission time Handle Problem Language Result Execution time Memory
440601 2021-07-02T14:03:00 Z zxcvbnm XOR Sum (info1cup17_xorsum) C++14
7 / 100
1600 ms 109632 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
const int L = 35;
map<ll, ll> mp[L];
ll calc(int left, int right, int mod) {
    if (left > right) return 0;

    auto it1 = mp[mod].upper_bound(right);
    it1--;
    auto it2 = mp[mod].lower_bound(left);
    it2--;

    ll ret = it1->second - it2->second;
    return ret;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<ll> cnt(L, 0);
    vector<ll> p(L);
    p[0] = 1LL;
    for(int i = 1; i < L; i++) {
        p[i] = p[i-1] * 2LL;
//        cout << p[i] << "\n";
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < L; j++) {
            mp[j][a[i]%p[j]]++;
        }
    }
    for(int i = 0; i < L; i++) {
        mp[i][-1] = 0;
    }


    for(int i = 0; i < L; i++) {
        ll add = 0;
        for(auto& j : mp[i]) {
            j.second += add;
            add = j.second;
        }
    }

    for(int i = 0; i < n; i++) {
        int x = a[i];
        for(int j = 0; j < L-1; j++) {
            if ((x+x) & p[j]) {
                cnt[j]++;
            }
//            cout << x << "\n";
            if (x & p[j]) {
                int left = 0;
                int right = p[j] - (x % p[j]) - 1;
//                cout << "[" << left << "," << right << "]" << "\n";
                cnt[j] += calc(left, right, j+1);
//                cnt[j] %= 2;
                left = p[j+1] - (x % p[j]);
                right = p[j+1] - 1;
                cnt[j] += calc(left, right, j+1);
//                cnt[j] %= 2;
//                cout << "[" << left << "," << right << "]" << "\n\n";
            } else {
                int left = p[j] - (x % p[j]);
                int right = (p[j+1]-1) - (x % p[j]);
                cnt[j] += calc(left, right, j+1);
//                cout << "[" << left << "," << right << "]\n\n";
//                cnt[j] %= 2;
            }
//            cout << cnt[j] << "\n";
        }
    }


    ll ans = 0;
    for(int i = 0; i < L; i++) {
        cnt[i] /= 2;
//        cout << cnt[i] << " ";
        if (cnt[i] % 2) {
            ans += p[i];
        }
    }
//    cerr << "\n";
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 110 ms 5964 KB Output is correct
2 Correct 92 ms 6032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1694 ms 14040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1694 ms 14040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 110 ms 5964 KB Output is correct
2 Correct 92 ms 6032 KB Output is correct
3 Execution timed out 1701 ms 109632 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 110 ms 5964 KB Output is correct
2 Correct 92 ms 6032 KB Output is correct
3 Execution timed out 1694 ms 14040 KB Time limit exceeded
4 Halted 0 ms 0 KB -