#include "bits/stdc++.h"
#define ff first
#define ss second
#define ll long long
using namespace std;
const int N = 1e6+5;
int a[N];
vector<int> val[2];
ll uly(vector<int> &A, vector<int> &B, int K){
ll cnt = 0;
int sz = (int)B.size() - 1;
int p = sz;
for (auto x: A){
while (p >= 0 and x+B[p]>=K)
p -= 1;
cnt += sz - p;
}
return cnt;
}
ll kici(vector<int> &A, vector<int> &B, int K){
return (ll)A.size()*(ll)B.size() - uly(A, B, K);
}
int main(){
// freopen("file.in", "r", stdin);
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", a+i);
vector<pair<int,int> > tries{{0,0}, {1,1}, {0, 1}};
int ans = 0;
for (int k = 0; k < 31; k++){
val[0].clear();
val[1].clear();
for (int i = 0; i < n; i++)
val[a[i]>>k&1].push_back(a[i]%(1<<k));
sort(val[0].begin(), val[0].end());
sort(val[1].begin(), val[1].end());
int K = (1<<k);
int n00 = uly(val[0], val[0], K); //p+q>=K
int n11 = uly(val[1], val[1], K); //p+q>=K
int n01 = kici(val[0], val[1], K); //p+q<K
//remove duplicates
for (auto A: val[0])
n00 += (A+A >= K);
n00 /= 2;
//remove duplicates
for (auto A: val[1])
n11 += (A+A >= K);
n11 /= 2;
int cnt = n00 + n11 + n01;
if (cnt&1)
ans |= (1<<k);
}
printf("%d\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
xorsum.cpp: In function 'int main()':
xorsum.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
xorsum.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d", a+i);
| ~~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |