이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
int ans = 0;
if (n % 2 == 0){
for (int j = 0; j < N; j++){
int cnt = 0;
for (int i = 0; i < n; i++){
if (a[i] & 1 << j)
cnt++;
}
ans ^= (cnt & 1) << j;
}
}
vector<pair<int, int>> res(n);
for (int i = 0; i < n; i++)
res[i] = make_pair(a[i] & 1, i);
sort(res.begin(), res.end());
auto calc = [&](int j) -> long long {
int r = n;
long long ret = 0;
for (int i = 0; i < n; i++){
while (r > 0 && res[r - 1].first >= (1 << j) - res[i].first) r--;
ret += n - r;
ret += res[i].first >= (1 << j - 1);
}
return ret;
};
long long cnt = calc(1) / 2;
ans ^= (cnt & 1) << 1;
for (int j = 2; j <= N; j++){
vector<pair<int, int>> b, c;
for (int i = 0; i < n; i++){
if (a[res[i].second] & 1 << j)
c.push_back(make_pair(res[i].first ^ 1 << j, res[i].second));
else
b.push_back(res[i]);
}
b.insert(b.end(), c.begin(), c.end());
swap(res, b);
cnt = calc(j) / 2;
ans ^= (cnt & 1) << j;
}
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
xorsum.cpp: In lambda function:
xorsum.cpp:32:44: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
32 | ret += res[i].first >= (1 << j - 1);
| ~~^~~
# | 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... |