#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
fast;
}
int n;
bool valid(int l,int r)
{
return l >= 0 and r <= n - 1 and l <= r;
}
int main()
{
setIO();
cin>>n;
vi v(n);
for (int i = 0;i<n;i++)
cin>>v[i];
ll ans = 0;
for (int b = 1;b<=29;b++){
vi bits(n);
for (int i = 0;i<n;i++){
int x = v[i];
int num = 0;
int cnt = 0;
vi digs;
while (x > 0 and cnt < b){
digs.pb(x%2);
x /= 2;
cnt++;
}
reverse(digs.begin(),digs.end());
for (int i = 0;i<digs.size();i++){
int pos = (digs.size() - i - 1);
num += digs[i] * (1<<pos);
}
bits[i] = num;
}
sort(bits.begin(),bits.end());
//sum of the 2 "b" bit (and hence (b - 1)th position)
//numbers should be
//in the range
//[1<<(b - 1), (1<<b) - 1]
//OR
//[(1<<b) + (1<<(b - 1)), (1<<(b + 1)) - 2]
bool is = 0;
for (int i = 0;i<n;i++){
int s1 = lower_bound(
bits.begin() + i,bits.end(), (1<<(b - 1)) - bits[i])
- bits.begin();
int e1 = -1;
int l = i,r = n - 1;
while (l <= r){
int mid = (l + r)/2;
if (bits[i] + bits[mid] <= (1<<b) - 1){
e1 = mid;
l = mid + 1;
}
else r = mid - 1;
}
int s2 = lower_bound(
bits.begin() + i,bits.end(),-bits[i] + (1<<b) +
(1<<(b - 1))) - bits.begin();
int e2 = -1;
l = i,r = n - 1;
while (l <= r){
int mid = (l + r)/2;
if (bits[i] + bits[mid] <= (1<<(b + 1)) - 2){
e2 = mid;
l = mid + 1;
}
else r = mid - 1;
}
int num = 0;
if (valid(s1,e1) and valid(s2,e2)){
if (e1 < s2)
num = (e1 - s1 + 1) + (e2 - s2 + 1);
else
num = (e2 - s1 + 1);
}
else if (valid(s1,e1))
num = e1 - s1 + 1;
else if (valid(s2,e2))
num = e2 - s2 + 1;
if (num&1)is = !is;
}
if (is)ans += (1<<(b - 1));
}
cout<<ans<<"\n";
return 0;
}
Compilation message
xorsum.cpp: In function 'int main()':
xorsum.cpp:49:29: 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<digs.size();i++){
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
332 KB |
Output is correct |
2 |
Correct |
30 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1676 ms |
8132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1676 ms |
8132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
332 KB |
Output is correct |
2 |
Correct |
30 ms |
332 KB |
Output is correct |
3 |
Correct |
843 ms |
1104 KB |
Output is correct |
4 |
Correct |
841 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
332 KB |
Output is correct |
2 |
Correct |
30 ms |
332 KB |
Output is correct |
3 |
Execution timed out |
1676 ms |
8132 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |