Submission #318951

# Submission time Handle Problem Language Result Execution time Memory
318951 2020-11-03T14:51:01 Z NachoLibre XOR Sum (info1cup17_xorsum) C++14
45 / 100
1600 ms 30092 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1000006, M = 30;
int n, a[N], x;
vector<pair<int, int> > v;

void nextsort(int b) {
	vector<pair<int, int> > nv[2];
	b = (1 << b);
	for(int i = 0; i < n; ++i) {
		v[i].first |= (a[v[i].second] & b);
		nv[!!(v[i].first & b)].push_back(v[i]);
	}
	v.clear();
	for(int i = 0; i < 2; ++i) {
		for(int j = 0; j < nv[i].size(); ++j) {
			v.push_back(nv[i][j]);
		}
	}
}

int xorcount(int b) {
	int r = n, dr = 0;
	b = (1 << b);
	for(int i = 0; i < n; ++i) {
		while(r > i && ((v[r - 1].first + v[i].first) & b)) --r;
		dr ^= ((n - r) & 1);
		if(r == i) ++r;
	}
	return dr;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		v.push_back({0, i});
		if((n & 1) ^ 1) x ^= a[i];
	}
	for(int i = 1; i < M; ++i) {
		nextsort(i - 1);
		x ^= (xorcount(i) << i);
	}
	cout << x << endl;
	return 0;
}

Compilation message

xorsum.cpp: In function 'void nextsort(int)':
xorsum.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for(int j = 0; j < nv[i].size(); ++j) {
      |                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1683 ms 30092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1683 ms 30092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 94 ms 3404 KB Output is correct
4 Correct 93 ms 3472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 492 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Execution timed out 1683 ms 30092 KB Time limit exceeded
4 Halted 0 ms 0 KB -