Submission #488562

# Submission time Handle Problem Language Result Execution time Memory
488562 2021-11-19T15:57:43 Z Drew_ XOR Sum (info1cup17_xorsum) C++17
0 / 100
470 ms 17736 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

// 0 <= x, y <= 2^(k+1)
// (x+y) & (2^k) > 0
// 2^k <= x+y < 2^(k+1)
// 2^(k+1) <= x+y < 2^(k+2)

int main()
{
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<int> v(n);
	for (int &x : v)
		cin >> x;

	int res = 0;
	for (int k = 0; k < 30; ++k)
	{
		// radix sort
		{
			vector<int> a, b;
			for (int &x : v)
			{
				if (x >> k & 1) b.pb(x);
				else a.pb(x);
			}

			v.clear();
			for (int x : a)
				v.pb(x);
			for (int x : b)
				v.pb(x);
		}

		int C = 0, R = (1 << (k+1)) - 1;
		int l = n-1, r = n-1;
		for (int x : v)
		{
			while (l >= 0 && (x&R) + (v[l]&R) >= (1 << k)) l--;
			while (r >= 0 && (x&R) + (v[r]&R) >= (1 << (k+1))) r--;
			C += r-l;
		}

		l = r = n-1;
		for (int x : v)
		{
			while (l >= 0 && (x&R) + (v[l]&R) >= (1 << (k+1)) + (1 << k)) l--;
			while (r >= 0 && (x&R) + (v[r]&R) >= (1 << (k+1)) + (1 << (k+1))) r--;
			C += r-l;
		}
		
		if (C & 1) res ^= (1 << k);
	}
	cout << res << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 470 ms 17736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 470 ms 17736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -