Submission #946616

#TimeUsernameProblemLanguageResultExecution timeMemory
946616n3rm1nGap (APIO16_gap)C++17
42.65 / 100
38 ms3692 KiB
#include<bits/stdc++.h> #include "gap.h" using namespace std; const long long MAXN = 2e5 + 10; long long a[MAXN]; long long findGap(int T, int N) { if(T == 1) { long long s = 0, t = (long long)(1e18); long long mn, mx; long long n = N; long long filled0 = 0, filled1 = n+1; while(filled0 + 1 <= filled1 - 1) { MinMax(s, t, &mn, &mx); if(mn == mx) { filled0 ++; a[filled0] = mn; n --; break; } filled0 ++; filled1 --; n-= 2; a[filled0] = mn; a[filled1] = mx; s = mn + 1; t = mx - 1; } long long ans = -1; //cout << "n is " << n << endl; //cout << a[1] << " "; for (long long i = 2; i <= N; ++ i) { //cout << a[i] << " "; ans = max(ans, (long long) (a[i] - a[i-1])); } //cout << endl; //cout << ans << endl; return ans; } long long s = 0, t = (long long)(1e18), mn, mx; MinMax(s, t, &mn, &mx); long long curr = mn, last = mx; long long ans = 1; deque < long long > q; while(curr < last) { // cout << curr << endl; // cout << "* " << ans << endl; s = curr + 1; t = curr + ans; if(s <= t) { MinMax(s, t, &mn, &mx); if(mn != -1 && mx != -1) { curr = mx; //cout << "move to " << curr << endl; continue; } } while(!q.empty() && q.front() <= curr) { q.pop_front(); } long long limit = last; if(!q.empty())limit = q.front(); long long lf = ans, rth = min(limit - curr, last - curr), mid, newans = -1; //q.clear(); long long found = 0; while(lf <= rth) { mid = (rth - lf)/2 + lf; s = curr + 1; t = curr + mid + 1; MinMax(s, t, &mn, &mx); if(mn == -1 && mx == -1) { lf = mid + 1; } else { rth = mid - 1; if(q.empty() || q.front() > mx)q.push_front(mx); found = mx; newans = mid; } } // cout << "found is " << found << endl; if(newans != -1)ans = found - curr; else break; curr = found; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...