Submission #318942

#TimeUsernameProblemLanguageResultExecution timeMemory
318942NachoLibreXOR Sum (info1cup17_xorsum)C++14
77 / 100
1589 ms39896 KiB
#include <bits/stdc++.h>
using namespace std;

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

void nextsort(int b) {
	vector<pair<int, int> > nv[2];
	for(int i = 0; i < n; ++i) {
		v[i].first |= (a[v[i].second] & (1 << b));
		nv[!!(v[i].first & (1 << 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;
	for(int i = 0; i < n; ++i) {
		while(r > i && ((v[r - 1].first + v[i].first) & (1 << 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 = 0; i < M; ++i) {
		x ^= (xorcount(i) << i);
		nextsort(i);
	}
	cout << x << endl;
	return 0;
}

Compilation message (stderr)

xorsum.cpp: In function 'void nextsort(int)':
xorsum.cpp:16: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]
   16 |   for(int j = 0; j < nv[i].size(); ++j) {
      |                  ~~^~~~~~~~~~~~~~
xorsum.cpp: In function 'int main()':
xorsum.cpp:39:8: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   39 |   if(n & 1 ^ 1) x ^= a[i];
      |      ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...