답안 #318946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
318946 2020-11-03T14:13:29 Z NachoLibre XOR Sum (info1cup17_xorsum) C++14
77 / 100
1473 ms 30544 KB
#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 = 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: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) {
      |                  ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1473 ms 30144 KB Output is correct
2 Correct 1293 ms 27108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1473 ms 30144 KB Output is correct
2 Correct 1293 ms 27108 KB Output is correct
3 Correct 1397 ms 29680 KB Output is correct
4 Correct 1302 ms 29160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 96 ms 3468 KB Output is correct
4 Correct 85 ms 3356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 1473 ms 30144 KB Output is correct
4 Correct 1293 ms 27108 KB Output is correct
5 Correct 1397 ms 29680 KB Output is correct
6 Correct 1302 ms 29160 KB Output is correct
7 Correct 96 ms 3468 KB Output is correct
8 Correct 85 ms 3356 KB Output is correct
9 Correct 1448 ms 30544 KB Output is correct
10 Correct 1418 ms 30440 KB Output is correct
11 Incorrect 1459 ms 30260 KB Output isn't correct