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 <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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |