Submission #440598

# Submission time Handle Problem Language Result Execution time Memory
440598 2021-07-02T13:59:56 Z zxcvbnm XOR Sum (info1cup17_xorsum) C++14
7 / 100
1600 ms 131076 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
const int L = 50;
map<ll, ll> mp[L];
map<ll, ll> prevs[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;
        prevs[i] = mp[i];
    }


    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-3; 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 140 ms 19316 KB Output is correct
2 Correct 142 ms 19264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1672 ms 17908 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1672 ms 17908 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 140 ms 19316 KB Output is correct
2 Correct 142 ms 19264 KB Output is correct
3 Runtime error 1245 ms 131076 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 140 ms 19316 KB Output is correct
2 Correct 142 ms 19264 KB Output is correct
3 Execution timed out 1672 ms 17908 KB Time limit exceeded
4 Halted 0 ms 0 KB -