Submission #106769

#TimeUsernameProblemLanguageResultExecution timeMemory
106769DiuvenGap (APIO16_gap)C++14
100 / 100
90 ms4144 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...