# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
98294 | 2019-02-21T22:46:53 Z | keko37 | XOR Sum (info1cup17_xorsum) | C++14 | 1600 ms | 42368 KB |
#include<bits/stdc++.h> using namespace std; typedef long long llint; const int MAXN = 1000005; int n; int a[MAXN], p[MAXN], s[MAXN], sol[35]; vector < pair <int, int> > v; void update (int k) { vector < pair <int, int> > nul, jen; for (int i=0; i<n; i++) { int val = v[i].first, ind = v[i].second; if (a[ind] & (1 << k)) { jen.push_back(make_pair(val + (1 << k), ind)); } else { nul.push_back(make_pair(val, ind)); } } v.clear(); for (int i=0; i<nul.size(); i++) v.push_back(nul[i]); for (int i=0; i<jen.size(); i++) v.push_back(jen[i]); } void ispis () { for (int i=0; i<v.size(); i++) { cout << v[i].first << " " << v[i].second << " "; } cout << endl; } void kth (int k) { for (int i=0; i<n; i++) { if (i > 0) p[i] = p[i-1]; else p[i] = 0; int val = v[i].first, ind = v[i].second; if (a[ind] & (1 << k)) p[i]++; } p[n] = p[n-1]; s[n] = 0; for (int i=n-1; i>=0; i--) { if (i < n-1) s[i] = s[i+1]; else s[i] = 0; int val = v[i].first, ind = v[i].second; if (a[ind] & (1 << k)) s[i]++; } llint res = 0; int curr = 0; for (int i=n-1; i>=0; i--) { while (curr < n && v[i].first + v[curr].first < (1 << k)) curr++; int val = v[i].first, ind = v[i].second; int tmp; if (curr == 0) tmp = 0; else tmp = p[curr-1]; if (a[ind] & (1 << k)) { res += curr - tmp + s[curr]; } else { res += tmp + n - curr - s[curr]; } if ((a[ind] + a[ind]) & (1 << k)) res++; } sol[k] = (res / 2) % 2; } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i=1; i<=n; i++) { cin >> a[i]; v.push_back(make_pair(0, i)); } int br = 0; for (int i=0; i<=30; i++) { kth(i); br += sol[i] * (1 << i); update(i); } cout << br << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 512 KB | Output is correct |
2 | Correct | 8 ms | 512 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1644 ms | 42368 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1644 ms | 42368 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 512 KB | Output is correct |
2 | Correct | 8 ms | 512 KB | Output is correct |
3 | Correct | 184 ms | 5100 KB | Output is correct |
4 | Correct | 169 ms | 5044 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 512 KB | Output is correct |
2 | Correct | 8 ms | 512 KB | Output is correct |
3 | Execution timed out | 1644 ms | 42368 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |