| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 872386 | racsosabe | XOR Sum (info1cup17_xorsum) | C++14 | 11 ms | 1372 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace::std;
const int N = 100000 + 5;
int n;
int a[N];
vector<pair<int, int>> parse(vector<int> &v) {
int l = 0;
vector<pair<int, int>> res;
while(l < v.size()) {
int r = l;
while(r < v.size() and v[l] == v[r]) r += 1;
res.emplace_back(v[l], r - l);
l = r;
}
return res;
}
long long get_crossed(vector<pair<int, int>> a, vector<pair<int, int>> b, int m) {
int sum_a = 0, sum_b = 0;
for(auto x : a) sum_a += x.second;
for(auto x : b) sum_b += x.second;
long long res = 1ll * sum_a * sum_b;
int at = b.size() - 1;
int sum = 0;
for(auto x : a) {
if(x.first == 0) continue;
int want = m - x.first;
while(at >= 0 and b[at].first >= want) {
sum += b[at].second;
at -= 1;
}
res -= 1ll * x.second * sum;
}
return res;
}
long long get_pairs(vector<pair<int, int>> v, int m) {
long long res = 0;
int at = (int)v.size() - 1;
int sum = 0;
for(int i = 0; i < v.size(); i++) {
if((v[i].first << 1) >= m) res += 1ll * v[i].second * (v[i].second - 1) / 2;
int want = m - v[i].first;
while(at >= 0 and v[at].first >= want) {
sum += v[at].second;
at -= 1;
}
if(v[i].first < want) res += 1ll * v[i].second * sum;
}
return res;
}
long long get_bits(int b, int p) {
vector<int> ones;
vector<int> zeros;
vector<int> total;
for(int i = 0; i < n; i++) {
if(a[i] & p) ones.emplace_back(a[i] % p);
else zeros.emplace_back(a[i] % p);
}
sort(ones.begin(), ones.end());
sort(zeros.begin(), zeros.end());
vector<pair<int, int>> p_ones = parse(ones), p_zeros = parse(zeros);
return get_crossed(p_ones, p_zeros, p) + get_pairs(p_ones, p) + get_pairs(p_zeros, p);
}
int main(){
scanf("%d", &n);
int X = 0, A = INT_MAX, O = 0;
for(int i = 0; i < n; i++) {
scanf("%d", a + i);
X ^= a[i] << 1;
A &= a[i] << 1;
O |= a[i] << 1;
}
for(int b = 0, p = 1; b < 31; b++, p <<= 1) {
long long cnt = get_bits(b, p);
if(cnt & 1) X ^= p;
if(cnt != 1ll * n * (n - 1) / 2) A &= ~p;
if(cnt) O |= p;
}
printf("%d\n", X);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
