답안 #67990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67990 2018-08-15T16:54:45 Z cdemirer XOR Sum (info1cup17_xorsum) C++17
100 / 100
1141 ms 24176 KB
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef pair<double, double> dodo;
typedef pair<ll, ll> llp;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)


ll N;
ll A[1000000];
ll B[1000000];
ll C[1000000];
int bcnt;
ll ans[31] = {0};

int main(int argc, char **argv) {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	
	for (ll k = 0; k < 30; k++) {
		bcnt = 0;
		for (int i = 0; i < N; i++) if (!(A[i] & (1<<k))) B[bcnt++] = (A[i]);
		for (int i = 0; i < N; i++) if ((A[i] & (1<<k))) B[bcnt++] = (A[i]);
		for (int i = 0; i < N; i++) A[i] = B[i];
		for (int i = 0; i < N; i++) C[i] = A[i] & ((1<<(k+1))-1);
		llp limits = mp(1<<k, (1<<(k+1))-1);
		llp range = mp(N-1, N-1);
		ll cnt = 0;
		for (int i = 0; i < N; i++) {
			while (range.first >= 0 && C[range.first] + C[i] >= limits.first) range.first--;
			while (range.second >= 0 && C[range.second] + C[i] > limits.second) range.second--;
			ans[k] += range.second - range.first;
			if (i > range.first && i <= range.second) cnt++;
		}
		ll limit = (1<<(k+1)) + (1<<k);
		range = mp(N-1, N-1);
		for (int i = 0; i < N; i++) {
			while (range.first >= 0 && C[range.first] + C[i] >= limit) range.first--;
			ans[k] += range.second - range.first;
			if (i > range.first && i <= range.second) cnt++;
		}
		ans[k] = (ans[k]+cnt)/2;
	}
	ll out = 0;
	for (int k = 0; k < 30; k++) {
		out |= ((ans[k]&1)<<k);
	}
	cout << out << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 468 KB Output is correct
2 Correct 7 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 634 ms 23968 KB Output is correct
2 Correct 579 ms 23968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 634 ms 23968 KB Output is correct
2 Correct 579 ms 23968 KB Output is correct
3 Correct 857 ms 24176 KB Output is correct
4 Correct 814 ms 24176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 468 KB Output is correct
2 Correct 7 ms 492 KB Output is correct
3 Correct 105 ms 24176 KB Output is correct
4 Correct 106 ms 24176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 468 KB Output is correct
2 Correct 7 ms 492 KB Output is correct
3 Correct 634 ms 23968 KB Output is correct
4 Correct 579 ms 23968 KB Output is correct
5 Correct 857 ms 24176 KB Output is correct
6 Correct 814 ms 24176 KB Output is correct
7 Correct 105 ms 24176 KB Output is correct
8 Correct 106 ms 24176 KB Output is correct
9 Correct 1106 ms 24176 KB Output is correct
10 Correct 1120 ms 24176 KB Output is correct
11 Correct 1141 ms 24176 KB Output is correct