Submission #906386

#TimeUsernameProblemLanguageResultExecution timeMemory
906386Trisanu_DasLightning Conductor (POI11_pio)C++17
100 / 100
183 ms14032 KiB
#include <bits/stdc++.h> using namespace std; struct point { int i, l, r; //[l...r] => segment of maximality }; int n, h[500005], dp[500005]; deque<point> hull; double f(int x, int i) { return h[i] + sqrt(abs(x - i)); } void solve() { hull.clear(); for(int i = 1; i <= n; ++i) { while(!hull.empty() && hull.front().r < i) hull.pop_front(); while(!hull.empty() && f(max(i, hull.back().l), hull.back().i) <= f(max(i, hull.back().l), i)) hull.pop_back(); if(hull.empty()) hull.push_back({i, i, n}); else { int l = max(i, hull.back().l), r = hull.back().r, ans = 0; while(l <= r) { int m = (l + r) / 2; if(f(m, i) >= f(m, hull.back().i)) ans = m, r = m - 1; else l = m + 1; } if(ans) { if(ans - 1 >= hull.back().l) hull.back().r = ans - 1; else hull.pop_back(); hull.push_back({i, ans, n}); } } dp[i] = max(dp[i], (int)ceil(f(i, hull.front().i)) - h[i]); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; i++) cin >> h[i]; solve(); reverse(h + 1, h + 1 + n); reverse(dp + 1, dp + 1 + n); solve(); for(int i = n; i; --i) cout << dp[i] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...