Submission #681909

# Submission time Handle Problem Language Result Execution time Memory
681909 2023-01-14T20:16:31 Z MilosMilutinovic XOR Sum (info1cup17_xorsum) C++14
45 / 100
1600 ms 18316 KB
#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 = 1010101;
const int LOG = 29;
int n;
int v[N];
vector<int> xs[2];

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++;
	}
	if (a * b % 2 != 0)
		ans ^= 1;
	for (int b = 1; b < LOG; b++) {
		for (int j = 0; j < 2; j++)
			xs[j].clear();
		for (int i = 0; i < n; i++) {
			int bit = (v[i] >> b & 1);
			xs[bit].push_back(v[i] & ((1 << b) - 1));
		}
		for (int j = 0; j < 2; j++)
			sort(xs[j].begin(), xs[j].end());
		ll c = 0;
		for (int x = 0; x < 2; x++) {
			for (int y = x; y < 2; y++) {
				if (x == y)
					c += calcSame(xs[x], xs[y], b);
				else
					c += calcDiff(xs[x], xs[y], b);
			}
		}
		if (c & 1) {
			ans += (1 << b);
		}
	}
	printf("%d\n", ans);

	return 0;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:59:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
xorsum.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   scanf("%d", &v[i]);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 8 ms 388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1665 ms 18316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1665 ms 18316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 8 ms 388 KB Output is correct
3 Correct 228 ms 1844 KB Output is correct
4 Correct 207 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 8 ms 388 KB Output is correct
3 Execution timed out 1665 ms 18316 KB Time limit exceeded
4 Halted 0 ms 0 KB -