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 <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, lint> pll;
pll ask(lint l, lint r){
pll res;
// cout<<"Ask: "<<l<<' '<<r<<'\n';
MinMax(l, r, &res.first, &res.second);
return res;
}
lint solve1(int n){
vector<lint> A;
lint s=1, e = 1e18;
while((int)A.size()<n){
pll now = ask(s,e);
A.push_back(now.first);
A.push_back(now.second);
s = now.first+1, e = now.second-1;
}
sort(A.begin(), A.end());
lint ans = 0;
for(int i=1; i<(int)A.size(); i++)
ans = max(ans, A[i]-A[i-1]);
return ans;
}
lint solve2(int n){
pll F = ask(1, 1e18);
lint s = F.first, e = F.second, l = (e-1)-(s+1)+1;
lint b = l/n;
vector<lint> V;
for(int i=0; i<n; i++) V.push_back(b + (i<l-b*n));
vector<pll> P;
{
lint now = s+1;
for(int i=0; i<n; i++){
if(V[i]<1){ P.push_back({-1,-1}); continue; }
pll res = ask(now, now+V[i]-1);
P.push_back(res);
now += V[i];
}
}
lint ans = 0;
{
lint last = s;
for(int i=0; i<n; i++){
if(P[i].first<0) continue;
lint now = P[i].first - last;
ans = max(ans, now);
last = P[i].second;
}
ans = max(ans, e-last);
}
return ans;
}
lint findGap(int T, int N){
if(T==1) return solve1(N);
else return solve2(N);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |