# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
128646 | E869120 | XOR Sum (info1cup17_xorsum) | C++14 | 1662 ms | 85860 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)
int N, A[1 << 20], S[1 << 24];
int solve(int bit) {
if (bit <= 22) {
for (int i = 0; i < (4 << bit); i++) S[i] = 0;
long long sum = 0; int TEISUU = (2 << bit);
for (int i = 1; i <= N; i++) {
S[A[i] & (TEISUU - 1)]++;
S[(A[i] & (TEISUU - 1)) + TEISUU]++;
}
for (int i = 1; i < (4 << bit); i++) S[i] += S[i - 1];
for (int i = 1; i <= N; i++) {
int F = (3 << bit) - (A[i] & (TEISUU - 1)); F &= (TEISUU - 1);
int pos1 = 0; if (F >= 1) pos1 = S[F - 1];
int pos2 = 0; if (F + (1 << bit) >= 1) pos2 = S[(F + (1 << bit)) - 1];
sum += 1LL * (pos2 - pos1);
}
long long sum2 = 0;
for (int i = 1; i <= N; i++) {
if (((A[i] + A[i]) & (TEISUU - 1)) >= (1 << bit)) sum2++;
}
return (sum2 + (sum - sum2) / 2LL) % 2LL;
}
else {
vector<int> vec; long long sum = 0; int TEISUU = (2 << bit);
for (int i = 1; i <= N; i++) {
vec.push_back(A[i] & (TEISUU - 1));
vec.push_back((A[i] & (TEISUU - 1)) + TEISUU);
}
sort(vec.begin(), vec.end());
for (int i = 1; i <= N; i++) {
int F = (3 << bit) - (A[i] & (TEISUU - 1)); F &= (TEISUU - 1);
int pos1 = lower_bound(vec.begin(), vec.end(), F) - vec.begin();
int pos2 = lower_bound(vec.begin(), vec.end(), F + (1 << bit)) - vec.begin();
sum += 1LL * (pos2 - pos1);
}
long long sum2 = 0;
for (int i = 1; i <= N; i++) {
if (((A[i] + A[i]) & (TEISUU - 1)) >= (1 << bit)) sum2++;
}
return (sum2 + (sum - sum2) / 2LL) % 2LL;
}
}
int main() {
scanf("%d", &N); int maxn = 0;
for (int i = 1; i <= N; i++) { scanf("%d", &A[i]); maxn = max(maxn, A[i]); }
int P = 0; for (int i = 0; i <= 30; i++) { if ((1 << i) <= maxn) P = i; }
int ans = 0;
for (int i = 0; i <= min(29, P + 1); i++) {
int t = solve(i);
if (t == 1) ans += (1 << i);
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | 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... |