# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
956213 | peteza | Gap (APIO16_gap) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gap.h"
#include <iostream>
#include <vector>
#include <utility>
using ll = long long;
const ll inf = 2e18;
long long findGap(int T, int N) {
if(T==1) {
ll cmin=0, cmax=inf, l=0, r=0;
std::vector<ll> v1, v2;
while(cmin <= cmax && v1.size() + v2.size() < N) {
MinMax(cmin, cmax, &l, &r);
if(l == -1) break;
v1.push_back(l); if(l != r) v2.push_back(r);
cmin = l+1; cmax = r-1;
}
ll amax = v2.back() - v1.back();
for(int i=0;i<v1.size()-1;i++) amax = std::max(amax, v1[i+1] - v1[i]);
for(int i=0;i<v2.size()-1;i++) amax = std::max(amax, v2[i] - v2[i+1]);
return amax;
} else {
ll rmin, rmax, l, r;
MinMax(0, inf, &rmin, &rmax);
ll amax = 1, i=1;
while(rmin < rmax) {
for(;i<=inf;i<<=1) {
MinMax(rmin+1, rmin+i, &l, &r);
if(l != -1) break;
}
if((i >> 1) >= amax) i >>= 1;
i = max(i, 1ll);
amax = std::max(amax, l-rmin);
rmin = r;
}
return amax;
}
}