/**
* author : pham van sam
* created : 27 June 2023 (Tuesday)
**/
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)
template <typename U, typename V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <typename U, typename V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }
const int MAXN = 1e6 + 5;
const int LOG = 30;
int N, a[MAXN];
int sum_xor(vector <int> a) {
int n = (int) a.size();
int ans = 0;
REP(bit, LOG) {
vector <int> bit0, bit1, b(n);
REP(i, n) (BIT(a[i], bit) ? bit1 : bit0).push_back(a[i]);
copy(ALL(bit0), a.begin());
copy(ALL(bit1), a.begin() + (int) bit0.size());
int j = n, k = n, l = n;
REP(i, n) b[i] = a[i] & (MASK(bit + 1) - 1);
REP(i, n) {
if(j < i) j = i;
if(k < i) k = i;
if(l < i) l = i;
while(j > i && b[j - 1] + b[i] >= MASK(bit)) --j;
while(k > i && b[k - 1] + b[i] >= MASK(bit + 1)) --k;
while(l > i && b[l - 1] + b[i] >= MASK(bit) + MASK(bit + 1)) --l;
if((k - j + n - l) & 1) ans ^= MASK(bit);
}
}
return ans;
}
void process(void) {
cin >> N;
REP(i, N) cin >> a[i];
cout << sum_xor(vector <int> (a, a + N));
}
signed main() {
#define TASK "TASK"
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
auto start_time = steady_clock::now();
int test = 1;
// cin >> test;
for (int i = 1; i <= test; ++i) {
process();
// cout << '\n';
}
auto end_time = steady_clock::now();
cerr << "\nExecution time : " << duration_cast<milliseconds> (end_time - start_time).count() << "[ms]" << endl;
return (0 ^ 0);
}
Compilation message
xorsum.cpp: In function 'int main()':
xorsum.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
xorsum.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
343 ms |
24936 KB |
Output is correct |
2 |
Correct |
317 ms |
23356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
343 ms |
24936 KB |
Output is correct |
2 |
Correct |
317 ms |
23356 KB |
Output is correct |
3 |
Correct |
363 ms |
27524 KB |
Output is correct |
4 |
Correct |
340 ms |
26840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
48 ms |
2460 KB |
Output is correct |
4 |
Correct |
44 ms |
2412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
343 ms |
24936 KB |
Output is correct |
4 |
Correct |
317 ms |
23356 KB |
Output is correct |
5 |
Correct |
363 ms |
27524 KB |
Output is correct |
6 |
Correct |
340 ms |
26840 KB |
Output is correct |
7 |
Correct |
48 ms |
2460 KB |
Output is correct |
8 |
Correct |
44 ms |
2412 KB |
Output is correct |
9 |
Correct |
443 ms |
30424 KB |
Output is correct |
10 |
Correct |
437 ms |
30736 KB |
Output is correct |
11 |
Correct |
433 ms |
30440 KB |
Output is correct |