#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int NMAX = 1e6+2;
int n,v[NMAX];
struct FenwickTree {
int n;
vector<int> aib;
FenwickTree(int _n){
n = _n;
aib.resize(n+1);
}
void update(int pos, int val){
pos++;
for(int i = pos; i <= n; i += (i&-i)){
aib[i] += val;
}
}
int query(int pos){
pos++;
if(pos <= 0){
return 0;
}
int ans = 0;
for(int i = pos; i > 0; i -= (i&-i)){
ans += aib[i];
}
return ans;
}
int query(int l, int r){
return query(r) - query(l-1);
}
};
int brut(int k){
int ans = 0;
int mod = (1<<(k+1));
int l = (1<<k), r = (1<<(k+1))-1;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= i; j++){
int sum = (v[i]+v[j])%mod;
int bt = (sum>>k)&1;
if(bt){
assert(l <= sum && sum <= r);
}
ans += bt;
}
}
return ans;
}
bool inauntru(int x, pii interv){
auto [l, r] = interv;
return (l <= x && x <= r);
}
int cnt(int k){
FenwickTree aib((1<<(k+1)));
int mod = (1<<(k+1));
int ans = 0;
for(int i = 1; i <= n; i++){
int val = v[i]%mod;
aib.update(val, 1);
int l = (1<<k), r = (1<<(k+1))-1;
l = (l-val+mod)%mod;
r = (r-val+mod)%mod;
if(l <= r){
ans += aib.query(l, r);
}else{
ans += aib.query(0, r);
ans += aib.query(l, mod-1);
}
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> v[i];
}
int ans = 0;
for(int i = 0; i < 20; i++){
ans += (cnt(i)&1)*(1<<i);
}
cout << ans;
return 0;
}
Compilation message
xorsum.cpp: In function 'bool inauntru(int, pii)':
xorsum.cpp:54:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
54 | auto [l, r] = interv;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
923 ms |
8708 KB |
Output is correct |
2 |
Correct |
879 ms |
12660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
923 ms |
8708 KB |
Output is correct |
2 |
Correct |
879 ms |
12660 KB |
Output is correct |
3 |
Correct |
810 ms |
15392 KB |
Output is correct |
4 |
Incorrect |
792 ms |
14888 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |