Submission #682677

# Submission time Handle Problem Language Result Execution time Memory
682677 2023-01-16T18:24:16 Z typ_ik XOR Sum (info1cup17_xorsum) C++17
56 / 100
1600 ms 14900 KB
#include <bits/stdc++.h>

#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define watch(x) cout << (#x) << " : " << x << '\n' 

using namespace std;

const int LOG = 30;

void solve() {
    int n;
    cin >> n;
    vector <int> a(n);
    for (auto& x : a)
        cin >> x;
    
    vector <int> cnt(LOG, 0);
    for (auto& x : a)
        for (int b = 0; b < LOG; b++)
            cnt[b] += (x >> b) & 1;

    int ans = 0;
    
    for (int b = 0; b < LOG; b++) {
        int pairs = 0;
        if (cnt[b] * (n - cnt[b]) & 1)
            pairs++; 

        int msk = (1 << b) - 1;
        vector <int> c(n);
        for (int i = 0; i < n; i++)
            c[i] = a[i] & msk;

        sort(all(c));
          
        int r = n; 
        for (int l = 0; l < n; l++) {
            while (r - 1 >= l && c[r - 1] + c[l] >= (1 << b))
                r--; 
            pairs += (n - max(l, r));
            pairs &= 1; 
        }  

        ans ^= (pairs << b);
    }

    cout << ans << '\n';
}

int32_t main() {
    boost;
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1545 ms 12736 KB Output is correct
2 Correct 1450 ms 11904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1545 ms 12736 KB Output is correct
2 Correct 1450 ms 11904 KB Output is correct
3 Execution timed out 1657 ms 14900 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 208 ms 2000 KB Output is correct
4 Correct 221 ms 1980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 1545 ms 12736 KB Output is correct
4 Correct 1450 ms 11904 KB Output is correct
5 Execution timed out 1657 ms 14900 KB Time limit exceeded
6 Halted 0 ms 0 KB -