Submission #488677

# Submission time Handle Problem Language Result Execution time Memory
488677 2021-11-20T00:40:57 Z Drew_ XOR Sum (info1cup17_xorsum) C++17
100 / 100
745 ms 22608 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#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);
		}

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

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

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 368 KB Output is correct
2 Correct 4 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 13160 KB Output is correct
2 Correct 451 ms 16164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 13160 KB Output is correct
2 Correct 451 ms 16164 KB Output is correct
3 Correct 599 ms 19672 KB Output is correct
4 Correct 553 ms 19368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 368 KB Output is correct
2 Correct 4 ms 336 KB Output is correct
3 Correct 79 ms 2572 KB Output is correct
4 Correct 77 ms 2468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 368 KB Output is correct
2 Correct 4 ms 336 KB Output is correct
3 Correct 500 ms 13160 KB Output is correct
4 Correct 451 ms 16164 KB Output is correct
5 Correct 599 ms 19672 KB Output is correct
6 Correct 553 ms 19368 KB Output is correct
7 Correct 79 ms 2572 KB Output is correct
8 Correct 77 ms 2468 KB Output is correct
9 Correct 745 ms 22572 KB Output is correct
10 Correct 733 ms 22608 KB Output is correct
11 Correct 736 ms 22584 KB Output is correct