Submission #918436

# Submission time Handle Problem Language Result Execution time Memory
918436 2024-01-29T20:29:54 Z divad XOR Sum (info1cup17_xorsum) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int NMAX = 1e6+2;
int n,v[NMAX];

struct FenwickTree {
    int n;
    vector<int> aib;
    FenwickTree(int _n){
        n = _n;
        aib.resize(n+1);
    }
    void update(int pos, int val){
        for(int i = pos; i <= n; i += (i&-i)){
            aib[i] += val;
        }
    }
    int query(int pos){
        int ans = 0;
        for(int i = pos; i > 0; i -= (i&-i)){
            ans += aib[i];
        }
        return ans;
    }
    int query(int l, int r){
        return query(r) - query(l-1);
    }
};

int brut(int k){
    int ans = 0;
    int mod = (1<<(k+1));
    int l = (1<<k), r = (1<<(k+1))-1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= i; j++){
            int sum = (v[i]+v[j])%mod;
            int bt = (sum>>k)&1;
            if(bt){
                assert(l <= sum && sum <= r);
            }
            ans += bt;
        }
    }
    return ans;
}

bool inauntru(int x, pii interv){
    auto [l, r] = interv;
    return (l <= x && x <= r);
}

int cnt(int k){
    int mod = (1<<(k+1));
    int ans = 0;
    vector<int> vals;
    for(int i = 1; i <= n; i++){
        int val = v[i]%mod;
        vals.push_back(val+1);
        int l = (1<<k), r = (1<<(k+1))-1;
        l = (l-val+mod)%mod;
        r = (r-val+mod)%mod;
        vals.push_back(r+1);
        vals.push_back(l);
    }
    sort(vals.begin(), vals.end());
    return 0;
    FenwickTree aib(cnt);
    int sum = 0;
    for(int i = 1; i <= n; i++){
        int val = v[i]%mod;
        sum++;
        aib.update(nrm[val+1], 1);
        int l = (1<<k), r = (1<<(k+1))-1;
        l = (l-val+mod)%mod;
        r = (r-val+mod)%mod;
        if(l <= r){
            ans += aib.query(nrm[r+1]) - aib.query(nrm[l]);
        }else{
            ans += aib.query(nrm[r+1]);
            ans += sum - aib.query(nrm[l]);
        }
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    int ans = 0;
    for(int i = 0; i < 30; i++){
        ans += (cnt(i)&1)*(1<<i);
    }
    cout << ans;
    return 0;
}

Compilation message

xorsum.cpp: In function 'bool inauntru(int, pii)':
xorsum.cpp:49:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   49 |     auto [l, r] = interv;
      |          ^
xorsum.cpp: In function 'int cnt(int)':
xorsum.cpp:68:21: error: invalid conversion from 'int (*)(int)' to 'int' [-fpermissive]
   68 |     FenwickTree aib(cnt);
      |                     ^~~
      |                     |
      |                     int (*)(int)
xorsum.cpp:10:21: note:   initializing argument 1 of 'FenwickTree::FenwickTree(int)'
   10 |     FenwickTree(int _n){
      |                 ~~~~^~
xorsum.cpp:73:20: error: 'nrm' was not declared in this scope
   73 |         aib.update(nrm[val+1], 1);
      |                    ^~~