제출 #197390

#제출 시각아이디문제언어결과실행 시간메모리
197390PankinXOR Sum (info1cup17_xorsum)C++14
100 / 100
1407 ms15096 KiB
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC optimize("-O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define mp make_pair #define ll long long #define ld long double #define pb push_back #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define fs first #define sc second #define getfiles ifstream cin("input.txt"); ofstream cout("output.txt"); #define endl '\n' #define pii pair<int, int> const int INF = 2000000005; const ll BIG_INF = 2000000000000000005; const int mod = 1000000007; const int P = 31; const ld PI = 3.141592653589793238462643; const double eps = 1e-9; using namespace std; const int N = 1000000 + 5; int order[N], p0[N], p1[N], o0, o1, a[N], n, ans = 0; inline int readint() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') { ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } return x; } signed main() { fast_io; n = readint(); int mx = 0; for (int i = 0; i < n; i++) { a[i] = readint(); mx = max(mx, a[i]); order[i] = i; } if (mx <= 1000000) mx = 21; else mx = 30; int curmask = 0; int pointer0 = o0, pointer1 = o1, same = 0, col = 0; for (int bit = 0; bit < mx; bit++) { o0 = o1 = 0; for (int i = 0; i < n; i++) { int v = (a[order[i]]>>bit)&1; if (v) { p1[o1] = order[i]; o1++; } else { p0[o0] = order[i]; o0++; } } pointer0 = o0, pointer1 = o1, same = 0, col = 0; for (int i = 0; i < n; i++) { while(pointer0 > 0 && (a[p0[pointer0 - 1]]&curmask) + (a[order[i]]&curmask) >= (1 << bit)) pointer0--; if (((a[order[i]]>>bit)&1) != 0) col += pointer0; else col += o0 - pointer0; while(pointer1 > 0 && (a[p1[pointer1 - 1]]&curmask) + (a[order[i]]&curmask) >= (1 << bit)) pointer1--; if (((a[order[i]]>>bit)&1) != 1) col += pointer1; else col += o1 - pointer1; if (((a[order[i]] + a[order[i]])>>bit)&1) same++; col &= 3; } col += 4 - (same&3); col >>= 1; col += same; ans |= ((col&1) << bit); int cur = 0; for (int i = 0; i < o0; i++) { order[cur] = p0[i]; cur++; } for (int i = 0; i < o1; i++) { order[cur] = p1[i]; cur++; } curmask <<= 1; curmask++; } cout << ans; return 0; } /* 2 7 0 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...