# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
681912 | 2023-01-14T20:56:44 Z | MilosMilutinovic | XOR Sum (info1cup17_xorsum) | C++14 | 1292 ms | 40872 KB |
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <array> using namespace std; typedef long long ll; const int N = 1000000; const int M = N * 15; const int LOG = 29; int n; int v[N]; vector<int> xs[2]; vector<int> ys[2]; int pos[N]; int id[N]; ll calcSame(vector<int> x, vector<int> y, int b) { assert(x == y); ll r = 0; int ptr = (int)y.size(); for (int i = 0; i < (int) x.size(); i++) { while(ptr > 0 && x[i] + y[ptr - 1] >= (1 << b)) ptr--; r += (int)y.size() - ptr; } for (int p : x) if (p + p >= (1 << b)) r++; return r / 2; } ll calcDiff(vector<int> x, vector<int> y, int b) { ll r = 0; int ptr = (int)y.size(); for (int i = 0; i < (int) x.size(); i++) { while(ptr > 0 && x[i] + y[ptr - 1] >= (1 << b)) ptr--; r += (int)y.size() - ptr; } return (ll)x.size() * y.size() - r; } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &v[i]); } int ans = 0; ll a = 0, b = 0; for (int i = 0; i < n; i++) { if (v[i] & 1) a++; else b++; } int T = 0; for (int j = 0; j < 2; j++) { for (int i = 0; i < n; i++) { if (v[i] % 2 == j) pos[i] = T++; } } if (a * b % 2 != 0) ans ^= 1; for (int b = 1; b < LOG; b++) { for (int i = 0; i < n; i++) id[pos[i]] = i; for (int j = 0; j < 2; j++) xs[j].clear(); for (int i = 0; i < n; i++) { int bit = (v[id[i]] >> b & 1); xs[bit].push_back(id[i]); } int t = 0; for (int j = 0; j < 2; j++) for (int i : xs[j]) pos[i] = t++; for (int j = 0; j < 2; j++) ys[j].clear(); for (int j = 0; j < 2; j++) { for (int i : xs[j]) { ys[j].push_back(v[i] & ((1 << b) - 1)); } } ll c = 0; for (int x = 0; x < 2; x++) { for (int y = x; y < 2; y++) { if (x == y) c += calcSame(ys[x], ys[y], b); else c += calcDiff(ys[x], ys[y], b); } } if (c & 1) { ans += (1 << b); } } printf("%d\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 468 KB | Output is correct |
2 | Correct | 4 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1123 ms | 34208 KB | Output is correct |
2 | Correct | 1047 ms | 36256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1123 ms | 34208 KB | Output is correct |
2 | Correct | 1047 ms | 36256 KB | Output is correct |
3 | Correct | 1208 ms | 40872 KB | Output is correct |
4 | Correct | 1069 ms | 39484 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 468 KB | Output is correct |
2 | Correct | 4 ms | 340 KB | Output is correct |
3 | Correct | 99 ms | 3188 KB | Output is correct |
4 | Correct | 102 ms | 3180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 468 KB | Output is correct |
2 | Correct | 4 ms | 340 KB | Output is correct |
3 | Correct | 1123 ms | 34208 KB | Output is correct |
4 | Correct | 1047 ms | 36256 KB | Output is correct |
5 | Correct | 1208 ms | 40872 KB | Output is correct |
6 | Correct | 1069 ms | 39484 KB | Output is correct |
7 | Correct | 99 ms | 3188 KB | Output is correct |
8 | Correct | 102 ms | 3180 KB | Output is correct |
9 | Correct | 1292 ms | 40632 KB | Output is correct |
10 | Correct | 1225 ms | 40596 KB | Output is correct |
11 | Incorrect | 1239 ms | 40516 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |