답안 #128650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128650 2019-07-11T08:00:09 Z E869120 XOR Sum (info1cup17_xorsum) C++14
77 / 100
1600 ms 77804 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N, A[1 << 20], S[1 << 24], V[1 << 21];

int solve(int bit) {
	if (bit <= 22) {
		for (int i = 0; i < (4 << bit); i++) S[i] = 0;
		long long sum = 0; int TEISUU = (2 << bit);
		for (int i = 1; i <= N; i++) {
			S[A[i] & (TEISUU - 1)]++;
			S[(A[i] & (TEISUU - 1)) + TEISUU]++;
		}
		for (int i = 1; i < (4 << bit); i++) S[i] += S[i - 1];

		for (int i = 1; i <= N; i++) {
			int F = (3 << bit) - (A[i] & (TEISUU - 1)); F &= (TEISUU - 1);
			int pos1 = 0; if (F >= 1) pos1 = S[F - 1];
			int pos2 = 0; if (F + (1 << bit) >= 1) pos2 = S[(F + (1 << bit)) - 1];
			sum += 1LL * (pos2 - pos1);
		}

		long long sum2 = 0;
		for (int i = 1; i <= N; i++) {
			if (((A[i] + A[i]) & (TEISUU - 1)) >= (1 << bit)) sum2++;
		}
		return (sum2 + (sum - sum2) / 2LL) % 2LL;
	}
	else {
		long long sum = 0; int TEISUU = (2 << bit);
		for (int i = 1; i <= N; i++) {
			V[i * 2 - 2] = A[i] & (TEISUU - 1);
			V[i * 2 - 1] = (A[i] & (TEISUU - 1)) + TEISUU;
		}
		sort(V, V + N * 2);

		for (int i = 1; i <= N; i++) {
			int F = (3 << bit) - (A[i] & (TEISUU - 1)); F &= (TEISUU - 1);
			int pos1 = lower_bound(V, V + N * 2, F) - V;
			int pos2 = lower_bound(V, V + N * 2, F + (1 << bit)) - V;
			sum += 1LL * (pos2 - pos1);
		}

		long long sum2 = 0;
		for (int i = 1; i <= N; i++) {
			if (((A[i] + A[i]) & (TEISUU - 1)) >= (1 << bit)) sum2++;
		}
		return (sum2 + (sum - sum2) / 2LL) % 2LL;
	}
}

int main() {
	scanf("%d", &N); int maxn = 0;
	for (int i = 1; i <= N; i++) { scanf("%d", &A[i]); maxn = max(maxn, A[i]); }

	int P = 0; for (int i = 0; i <= 30; i++) { if ((1 << i) <= maxn) P = i; }

	int ans = 0;
	for (int i = 0; i <= min(29, P + 1); i++) {
		int t = solve(i);
		if (t == 1) ans += (1 << i);
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

xorsum.cpp:5:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
xorsum.cpp: In function 'int main()':
xorsum.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N); int maxn = 0;
  ~~~~~^~~~~~~~~~
xorsum.cpp:57:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= N; i++) { scanf("%d", &A[i]); maxn = max(maxn, A[i]); }
                                 ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 66040 KB Output is correct
2 Correct 172 ms 66032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 4332 KB Output is correct
2 Correct 220 ms 4088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 4332 KB Output is correct
2 Correct 220 ms 4088 KB Output is correct
3 Correct 433 ms 20840 KB Output is correct
4 Correct 420 ms 20728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 66040 KB Output is correct
2 Correct 172 ms 66032 KB Output is correct
3 Correct 524 ms 67192 KB Output is correct
4 Correct 527 ms 67192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 66040 KB Output is correct
2 Correct 172 ms 66032 KB Output is correct
3 Correct 236 ms 4332 KB Output is correct
4 Correct 220 ms 4088 KB Output is correct
5 Correct 433 ms 20840 KB Output is correct
6 Correct 420 ms 20728 KB Output is correct
7 Correct 524 ms 67192 KB Output is correct
8 Correct 527 ms 67192 KB Output is correct
9 Execution timed out 1644 ms 77804 KB Time limit exceeded
10 Halted 0 ms 0 KB -