# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
128663 | 2019-07-11T08:13:27 Z | E869120 | XOR Sum (info1cup17_xorsum) | C++14 | 1090 ms | 106568 KB |
#include <iostream> #include <vector> #include <algorithm> using namespace std; #pragma warning (disable: 4996) const int THRESHOLD = 23; int N, A[1 << 20], S[1 << 24], V[1 << 21]; pair<int, int> U[1 << 20]; pair<int, int> U0[1 << 20]; pair<int, int> U1[1 << 20]; void making(int bit) { if (bit == THRESHOLD) { int TEISUU = (2 << bit) - 1; for (int i = 1; i <= N; i++) U[i - 1] = make_pair((A[i] & TEISUU), i); sort(U, U + N); } else { int c1 = 0, c2 = 0, TEISUU = (2 << bit) - 1; for (int i = 0; i < N; i++) { if ((A[U[i].second] & TEISUU) < (1 << bit)) { U0[c1] = make_pair((A[U[i].second] & TEISUU), U[i].second); c1++; } if ((A[U[i].second] & TEISUU) >= (1 << bit)) { U1[c2] = make_pair((A[U[i].second] & TEISUU), U[i].second); c2++; } } for (int i = 0; i < c1; i++) U[i] = U0[i]; for (int i = 0; i < c2; i++) U[i + c1] = U1[i]; } for (int i = 0; i < N; i++) V[i] = U[i].first; for (int i = 0; i < N; i++) V[i + N] = V[i] + (2 << bit); } int solve(int bit) { if (bit <= THRESHOLD - 1) { 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 { making(bit); int TEISUU = (2 << bit); long long sum = 0; int c1 = 0, c2 = 0; for (int i = N - 1; i >= 0; i--) { int F1 = (3 << bit) - (U[i].first & (TEISUU - 1)); int F2 = (4 << bit) - (U[i].first & (TEISUU - 1)); while (c1 < N * 2 && V[c1] < F1) c1++; while (c2 < N * 2 && V[c2] < F2) c2++; sum += 1LL * (c2 - c1); } 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 160 ms | 66180 KB | Output is correct |
2 | Correct | 162 ms | 66168 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 236 ms | 4292 KB | Output is correct |
2 | Correct | 219 ms | 4088 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 236 ms | 4292 KB | Output is correct |
2 | Correct | 219 ms | 4088 KB | Output is correct |
3 | Correct | 423 ms | 20788 KB | Output is correct |
4 | Correct | 403 ms | 20472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 160 ms | 66180 KB | Output is correct |
2 | Correct | 162 ms | 66168 KB | Output is correct |
3 | Correct | 244 ms | 69240 KB | Output is correct |
4 | Correct | 246 ms | 69240 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 160 ms | 66180 KB | Output is correct |
2 | Correct | 162 ms | 66168 KB | Output is correct |
3 | Correct | 236 ms | 4292 KB | Output is correct |
4 | Correct | 219 ms | 4088 KB | Output is correct |
5 | Correct | 423 ms | 20788 KB | Output is correct |
6 | Correct | 403 ms | 20472 KB | Output is correct |
7 | Correct | 244 ms | 69240 KB | Output is correct |
8 | Correct | 246 ms | 69240 KB | Output is correct |
9 | Correct | 1086 ms | 97232 KB | Output is correct |
10 | Correct | 1090 ms | 106568 KB | Output is correct |
11 | Correct | 1080 ms | 106536 KB | Output is correct |