이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |