이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<int> a(n), ord(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
ord[i] = i;
}
int ans = 0;
for (int bit = 0; bit < 31; bit++) {
// sort
vector<int> zeroBit, oneBit, vec(n);
for (int u : ord) {
if ((a[u] >> bit) & 1) oneBit.push_back(u);
else zeroBit.push_back(u);
}
ord = zeroBit, ord.insert(ord.end(), all(oneBit));
// last (`bit` + 1) bits
for (int i = 0; i < n; i++)
vec[i] = a[ord[i]] & ((1 << (bit + 1)) - 1);
// calculate
for (int i = 0; i < ord.size(); i++) {
int zero = -1, one = -1, two = -1;
for (int step = i + 1; step >= 1; step /= 2) {
while (zero + step <= i && ((vec[zero + step] + vec[i]) >> bit) <= 0) zero += step;
while (one + step <= i && ((vec[one + step] + vec[i]) >> bit) <= 1) one += step;
while (two + step <= i && ((vec[two + step] + vec[i]) >> bit) <= 2) two += step;
}
int cntOne = one - zero + i - two;
if (cntOne & 1) ans ^= (1 << bit);
}
}
cout << ans << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
xorsum.cpp: In function 'int main()':
xorsum.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < ord.size(); 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... |