Submission #1315866

#TimeUsernameProblemLanguageResultExecution timeMemory
1315866penguin133XOR Sum (info1cup17_xorsum)C++20
Compilation error
0 ms0 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int n, a[1000005];

int main() {
	cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < 30; i++) {
        vector <int> v;
        int mx = 0;
        for (int j = 1; j <= n; j++) {
          int x = a[j] % (1ll<<(i + 1));
          mx = max(mx, a[j]);
            v.push_back(mx);
        }
        if (mx < (1ll<<(i - 1)) break;
        sort(v.begin(), v.end());
        long long tmp = 0, tmp2 = 0;
        for (int j = 1; j <= n; j++) {
            int x = a[j] % (1ll<<(i + 1));
            int l = (1ll<<i) - x, r = (1ll<<(i + 1)) - 1 - x;
            if(l >= 0) {
                tmp += upper_bound(v.begin(), v.end(), r) - lower_bound(v.begin(), v.end(), l);
                if (l <= x && x <= r) tmp--, tmp2++;
            }
            else {
                tmp += v.end() - lower_bound(v.begin(), v.end(), l + (1ll<<(i + 1)));
                tmp += upper_bound(v.begin(), v.end(), r) - v.begin();
                if (x <= r || x >= l + (1ll<<(i + 1))) tmp--, tmp2++;
            }
            //cout << tmp << ' ';
        }
        tmp /= 2; tmp += tmp2;
        //cout << tmp << '\n';
        //tmp /= 2;
        if (tmp & 1) ans ^= (1ll<<i);
    }
    cout << ans;
}

Compilation message (stderr)

xorsum.cpp: In function 'int main()':
xorsum.cpp:20:32: error: expected ';' before 'break'
   20 |         if (mx < (1ll<<(i - 1)) break;
      |                                ^~~~~~
      |                                ;
xorsum.cpp:21:33: error: expected ')' before ';' token
   21 |         sort(v.begin(), v.end());
      |                                 ^
      |                                 )
xorsum.cpp:20:12: note: to match this '('
   20 |         if (mx < (1ll<<(i - 1)) break;
      |            ^
xorsum.cpp:21:13: error: could not convert 'std::sort<__gnu_cxx::__normal_iterator<int*, vector<int> > >(v.std::vector<int>::begin(), v.std::vector<int>::end())' from 'void' to 'bool'
   21 |         sort(v.begin(), v.end());
      |         ~~~~^~~~~~~~~~~~~~~~~~~~
      |             |
      |             void