#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 ("O2")
#pragma GCC optimization ("unroll-loops")
int64_t res (vector<int>& a, int x) {
//how many are <= x
int64_t r = a.size() - 1;
int64_t 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);
}
ans /= 2;
for (int i = 0; i < a.size(); i++) {
ans += (2 * a[i] <= x);
}
return ans;
}
int64_t comp (vector<int>&a, vector<int>&b, int x) {
//ans += res(a, x);
//ans += res(b, x);
int64_t r = b.size() - 1;
int64_t ans = res(a, x) + res(b, x);
for (int i = 0; i < a.size(); i++) {
if (a[i] + b[0] > x) {
break;
}
while (b[r] + a[i] > x) {
r--;
}
ans += abs(r) + 1;
}
return ans;
}
int64_t comp (vector<int>&a, vector<int>&b, int l, int r) {
return comp(a, b, r) - comp(a, b, 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];
}
sort(v.begin(), v.end());
int64_t ans = 0;
for (int b = 30; b >= 0; b--) {
vector<int> myVector;
vector<int> v1;
for (int i = 0; i < v.size(); i++) {
if (!(v[i] & (1 << b))) myVector.push_back(v[i] & ((1 << (b + 1)) - 1));
else v1.push_back(v[i] & ((1 << (b + 1)) - 1));
}
sort(myVector.begin(), myVector.end());
sort(v1.begin(), v1.end());
int64_t a = 0;
a += comp(v1, myVector, (1 << b), (1 << (b + 1)) - 1);
a += comp(v1, myVector, (1 << b) + (1 << (b + 1)), (1 << (b + 2)) - 1);
ans += ((int64_t)1 << b) * (a % 2);
}
cout << ans;
}
Compilation message
xorsum.cpp:14: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
14 | #pragma GCC optimization ("O2")
|
xorsum.cpp:15: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
15 | #pragma GCC optimization ("unroll-loops")
|
xorsum.cpp: In function 'int64_t 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:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
xorsum.cpp: In function 'int64_t comp(std::vector<int>&, std::vector<int>&, int)':
xorsum.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
xorsum.cpp: In function 'int main()':
xorsum.cpp:67:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
999 ms |
12940 KB |
Output is correct |
2 |
Correct |
912 ms |
13052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
999 ms |
12940 KB |
Output is correct |
2 |
Correct |
912 ms |
13052 KB |
Output is correct |
3 |
Correct |
1387 ms |
12884 KB |
Output is correct |
4 |
Correct |
1306 ms |
12032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
340 KB |
Output is correct |
3 |
Correct |
202 ms |
1612 KB |
Output is correct |
4 |
Correct |
197 ms |
1636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
384 KB |
Output is correct |
2 |
Correct |
8 ms |
340 KB |
Output is correct |
3 |
Correct |
999 ms |
12940 KB |
Output is correct |
4 |
Correct |
912 ms |
13052 KB |
Output is correct |
5 |
Correct |
1387 ms |
12884 KB |
Output is correct |
6 |
Correct |
1306 ms |
12032 KB |
Output is correct |
7 |
Correct |
202 ms |
1612 KB |
Output is correct |
8 |
Correct |
197 ms |
1636 KB |
Output is correct |
9 |
Execution timed out |
1684 ms |
12276 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |