제출 #1150839

#제출 시각아이디문제언어결과실행 시간메모리
1150839sunnatXOR Sum (info1cup17_xorsum)C++20
100 / 100
370 ms8264 KiB
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++ i){
        cin >> b[i];
    }
    int res = 0, k, v;
    
    for(int i = 0, n0 = 0, mod = 0, n1 = 0; i <= 30; ++ i){
        n0 = n1 = 0;
        mod = mod << 1 | 1;
        for(int j = 0; j < n; ++ j)
            if((b[j]>>i)&1)
                b[n1 ++] = b[j];
            else
                a[n0 ++] = b[j];
        for(int j = n1, t = 0; j < n; ++ j, ++ t)
            b[j] = a[t];
        for(int j = 0; j < n; ++ j)
            a[j] = b[j] & mod;
        
        k = 0;
        for(int j = 0, p = n - 1, q = n-1, w = n - 1; j < n; ++ j){
            if(j < n1){
                v = (1<<(i+1))-a[j] - 1;
                p = max(p, j);
                while(p >= j && a[p] <= v) -- p;
                
                k ^= (n - 1 - p) & 1;
                
                v = (3<<i) - a[j];
                q = max(q, j);
                while(q >= j && a[q] < v) -- q;
                k ^= (q - j + 1) & 1;
            }
            else{
                v = (1<<i) - a[j];
                w = max(w, j);
                while(w >= j && a[w] < v) -- w;
                k ^= (w - j + 1) & 1;
            }
        }
        if(k) res |= 1<<i;
         
    }
    
    
    cout << res << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...