Submission #682680

# Submission time Handle Problem Language Result Execution time Memory
682680 2023-01-16T18:33:05 Z typ_ik XOR Sum (info1cup17_xorsum) C++17
100 / 100
461 ms 21388 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++) {
        auto replace = [&]() -> void {
            int pt = n - cnt[b], l = 0;
            vector <int> c(n);
            for (int i = 0; i < n; i++)
                if ((a[i] >> b) & 1) c[pt++] = a[i];
                else c[l++] = a[i];
            swap(a, c); 
        };

        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; 

        replace(); 
          
        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 3 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 12064 KB Output is correct
2 Correct 332 ms 11368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 12064 KB Output is correct
2 Correct 332 ms 11368 KB Output is correct
3 Correct 306 ms 12308 KB Output is correct
4 Correct 318 ms 18116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 41 ms 1748 KB Output is correct
4 Correct 42 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 246 ms 12064 KB Output is correct
4 Correct 332 ms 11368 KB Output is correct
5 Correct 306 ms 12308 KB Output is correct
6 Correct 318 ms 18116 KB Output is correct
7 Correct 41 ms 1748 KB Output is correct
8 Correct 42 ms 1748 KB Output is correct
9 Correct 461 ms 21376 KB Output is correct
10 Correct 444 ms 21388 KB Output is correct
11 Correct 452 ms 21372 KB Output is correct