Submission #551104

#TimeUsernameProblemLanguageResultExecution timeMemory
551104OlympiaXOR Sum (info1cup17_xorsum)C++17
7 / 100
1688 ms8132 KiB
#include <iostream> #include <vector> #include <iomanip> #include <algorithm> #include <cassert> #include <map> #include <complex> #include <cmath> #include <set> #include <queue> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") int res (vector<int>& a, int x) { //how many are <= x int r = a.size() - 1; int ans = 0; for (int i = 0; i < a.size(); i++) { if (a[i] + a[0] > x) { break; } while (a[r] + a[i] > x) { r--; } ans += abs(r) + 1 - (r >= i); } assert(ans % 2 == 0); ans /= 2; for (int i = 0; i < a.size(); i++) { ans += (2 * a[i] <= x); } return ans; } int res (vector<int>& a, int l, int r) { return res(a, r) - res(a, l - 1); } int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int ans = 0; for (int b = 0; b < 31; b++) { vector<int> a(n); for (int i = 0; i < a.size(); i++) { a[i] = v[i] & ((1 << (b + 1)) - 1); } sort(a.begin(), a.end()); int r = 0; r += res(a, (1 << b), (1 << (b + 1)) - 1); r += res(a, (1 << b) + (1 << (b + 1)), (1 << (b + 2)) - 1); ans += (1 << b) * (r % 2); } cout << ans; }

Compilation message (stderr)

xorsum.cpp:14: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   14 | #pragma GCC optimization ("O3")
      | 
xorsum.cpp:15: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   15 | #pragma GCC optimization ("unroll-loops")
      | 
xorsum.cpp: In function 'int res(std::vector<int>&, int)':
xorsum.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < a.size(); i++) {
      |                     ~~^~~~~~~~~~
xorsum.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i < a.size(); i++) {
      |                     ~~^~~~~~~~~~
xorsum.cpp: In function 'int main()':
xorsum.cpp:49:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (int i = 0; i < a.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...