Submission #1110775

#TimeUsernameProblemLanguageResultExecution timeMemory
1110775_callmelucianXOR Sum (info1cup17_xorsum)C++14
45 / 100
1639 ms26776 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tpl; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n), ord(n); for (int i = 0; i < n; i++) { cin >> a[i]; ord[i] = i; } int ans = 0; for (int bit = 0; bit < 31; bit++) { // sort vector<int> zeroBit, oneBit, vec(n); for (int u : ord) { if ((a[u] >> bit) & 1) oneBit.push_back(u); else zeroBit.push_back(u); } ord = zeroBit, ord.insert(ord.end(), all(oneBit)); // last (`bit` + 1) bits for (int i = 0; i < n; i++) vec[i] = a[ord[i]] & ((1 << (bit + 1)) - 1); // calculate for (int i = 0; i < ord.size(); i++) { int zero = -1, one = -1, two = -1; for (int step = i + 1; step >= 1; step /= 2) { while (zero + step <= i && ((vec[zero + step] + vec[i]) >> bit) <= 0) zero += step; while (one + step <= i && ((vec[one + step] + vec[i]) >> bit) <= 1) one += step; while (two + step <= i && ((vec[two + step] + vec[i]) >> bit) <= 2) two += step; } int cntOne = one - zero + i - two; if (cntOne & 1) ans ^= (1 << bit); } } cout << ans << "\n"; return 0; }

Compilation message (stderr)

xorsum.cpp: In function 'int main()':
xorsum.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for (int i = 0; i < ord.size(); i++) {
      |                         ~~^~~~~~~~~~~~
#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...