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;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, i, cur = 0, at = 0;
cin >> n;
vector<int> h(n), ans(n);
for (i = 0; i < n; i++) cin >> h[i];
vector<int> hull = {0};
for (i = 1; i < n; i++) {
if (h[i] > h[hull.back()]) hull.push_back(i);
}
for (i = 0; i < n; i++) {
if (at < hull.size() - 1 and hull[at + 1] == i) at++;
while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[at]] + sqrt(i - hull[at])) cur = at;
ans[i] = max(ans[i], (int) ceil(h[hull[cur]] + sqrt(i - hull[cur]) - 1e-8));
}
reverse(h.begin(), h.end());
reverse(ans.begin(), ans.end());
hull = {0};
for (i = 1; i < n; i++) {
if (h[i] > h[hull.back()]) hull.push_back(i);
}
cur = 0, at = 0;
for (i = 0; i < n; i++) {
if (at < hull.size() - 1 and hull[at + 1] == i) at++;
while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[at]] + sqrt(i - hull[at])) cur = at;
ans[i] = max(ans[i], (int) ceil(h[hull[cur]] + sqrt(i - hull[cur]) - 1e-8));
}
reverse(ans.begin(), ans.end());
reverse(h.begin(), h.end());
for (i = 0; i < n; i++) cout << max(0, ans[i] - h[i]) << endl;
return 0;
}
Compilation message (stderr)
pio.cpp: In function 'int main()':
pio.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | if (at < hull.size() - 1 and hull[at + 1] == i) at++;
| ~~~^~~~~~~~~~~~~~~~~
pio.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[at]] + sqrt(i - hull[at])) cur = at;
| ~~~~^~~~~~~~~~~~~~~~~
pio.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | if (at < hull.size() - 1 and hull[at + 1] == i) at++;
| ~~~^~~~~~~~~~~~~~~~~
pio.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | while (cur < hull.size() - 1 and hull[cur] < i and h[hull[cur]] + sqrt(i - hull[cur]) < h[hull[at]] + sqrt(i - hull[at])) cur = at;
| ~~~~^~~~~~~~~~~~~~~~~
# | 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... |