#include <bits/stdc++.h>
// author : aykhn
using namespace std;
typedef long long ll;
#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcountll
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define int ll
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F
const int MXN = 1e5 + 5;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int res = 0;
for (int j = 0; j < 30; j++)
{
int b[n];
for (int i = 0; i < n; i++) b[i] = (a[i] & (1 << (j + 1)) - 1);
sort(b, b + n);
int c = 0;
for (int i = 0; i < n; i++)
{
int l = lower_bound(b, b + n, (1 << j) - b[i]) - b;
int r = lower_bound(b, b + n, (1 << (j + 1)) - b[i]) - b;
l = max(l, i);
if (l < r) c += r - l;
l = lower_bound(b, b + n, ((1 << (j + 1)) | (1 << j)) - b[i]) - b;
r = lower_bound(b, b + n, (1 << (j + 2)) - b[i]) - b;
l = max(l, i);
if (l < r) c += r - l;
}
if (c & 1) res |= (1 << j);
}
cout << res << '\n';
}
// ignore (i + 1 -> 23];
// a[i] &= (1 << (i + 1)) - 1;
// (1 << i) <= a[i] + a[j] < (1 << (i + 1));
// (1 << (i + 1)) | (1 << i) <= a[i] + a[j] < (1 << (i + 2))
Compilation message
xorsum.cpp: In function 'int main()':
xorsum.cpp:35:67: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
35 | for (int i = 0; i < n; i++) b[i] = (a[i] & (1 << (j + 1)) - 1);
| ~~~~~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
348 KB |
Output is correct |
2 |
Correct |
15 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1667 ms |
15956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1667 ms |
15956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
348 KB |
Output is correct |
2 |
Correct |
15 ms |
512 KB |
Output is correct |
3 |
Correct |
411 ms |
1884 KB |
Output is correct |
4 |
Correct |
414 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
348 KB |
Output is correct |
2 |
Correct |
15 ms |
512 KB |
Output is correct |
3 |
Execution timed out |
1667 ms |
15956 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |