# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
681913 | MilosMilutinovic | XOR Sum (info1cup17_xorsum) | C++14 | 1433 ms | 34432 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 <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
using namespace std;
typedef long long ll;
const int N = 1000001;
const int LOG = 30;
int n;
int v[N];
vector<int> xs[2];
vector<int> ys[2];
int pos[N];
int id[N];
ll calcSame(vector<int> x, vector<int> y, int b) {
assert(x == y);
ll r = 0;
int ptr = (int)y.size();
for (int i = 0; i < (int) x.size(); i++) {
while(ptr > 0 && x[i] + y[ptr - 1] >= (1 << b)) ptr--;
r += (int)y.size() - ptr;
}
for (int p : x)
if (p + p >= (1 << b))
r++;
return r / 2;
}
ll calcDiff(vector<int> x, vector<int> y, int b) {
ll r = 0;
int ptr = (int)y.size();
for (int i = 0; i < (int) x.size(); i++) {
while(ptr > 0 && x[i] + y[ptr - 1] >= (1 << b)) ptr--;
r += (int)y.size() - ptr;
}
return (ll)x.size() * y.size() - r;
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &v[i]);
}
int ans = 0;
ll a = 0, b = 0;
for (int i = 0; i < n; i++) {
if (v[i] & 1)
a++;
else
b++;
}
int T = 0;
for (int j = 0; j < 2; j++) {
for (int i = 0; i < n; i++) {
if (v[i] % 2 == j)
pos[i] = T++;
}
}
if (a * b % 2 != 0)
ans ^= 1;
for (int b = 1; b < LOG; b++) {
for (int i = 0; i < n; i++)
id[pos[i]] = i;
for (int j = 0; j < 2; j++)
xs[j].clear();
for (int i = 0; i < n; i++) {
int bit = (v[id[i]] >> b & 1);
xs[bit].push_back(id[i]);
}
int t = 0;
for (int j = 0; j < 2; j++)
for (int i : xs[j])
pos[i] = t++;
for (int j = 0; j < 2; j++)
ys[j].clear();
for (int j = 0; j < 2; j++) {
for (int i : xs[j]) {
ys[j].push_back(v[i] & ((1 << b) - 1));
}
}
ll c = 0;
for (int x = 0; x < 2; x++) {
for (int y = x; y < 2; y++) {
if (x == y)
c += calcSame(ys[x], ys[y], b);
else
c += calcDiff(ys[x], ys[y], b);
}
}
if (c & 1) {
ans += (1 << b);
}
}
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... |