Submission #886956

#TimeUsernameProblemLanguageResultExecution timeMemory
886956Zero_OPXOR Sum (info1cup17_xorsum)C++14
0 / 100
298 ms15328 KiB
#include<bits/stdc++.h> using namespace std; #define range(v) begin(v), end(v) #define compact(v) v.erase(unique(range(v)), end(v)) template<class T> bool minimize(T& a, T b){ if(a > b) return a = b, true; return false; } template<class T> bool maximize(T& a, T b){ if(a < b) return a = b, true; return false; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; int n; vector<int> a; void radixSort(int b){ vector<int> lastZero, lastOne; for(int i = 0; i < n; ++i){ if(a[i] >> b & 1){ lastOne.push_back(a[i]); } else{ lastZero.push_back(a[i]); } } a = lastZero; a.insert(a.begin(), range(lastOne)); } void Zero_OP(){ cin >> n; a = vector<int>(n); for(int i = 0; i < n; ++i){ cin >> a[i]; } sort(range(a)); int ans = 0; for(int target = 30; target >= 0; --target){ //last target bits radixSort(target); ll cur = 0; int j = n, k = n, l = n; for(int i = 0; i < n; ++i){ maximize(j, i); maximize(k, i); maximize(l, i); while(i < j and a[i] + a[j - 1] >= (1 << target)) --j; while(i < k and a[i] + a[k - 1] > ((1 << (target + 1)) - 1)) --k; while(i < l and a[i] + a[l - 1] >= (1 << (target + 1)) + (1 << target)) --l; cur += k - j; cur += n - l; } if(cur & 1) ans ^= (1 << target); } cout << ans << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #define task "antuvu" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } Zero_OP(); return 0; }

Compilation message (stderr)

xorsum.cpp: In function 'int main()':
xorsum.cpp:76:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |     freopen(task".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
xorsum.cpp:77:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |     freopen(task".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...