# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
795378 | nonono | Lightning Conductor (POI11_pio) | C++14 | 169 ms | 27596 KiB |
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;
const int mxN = 5e5 + 10;
int n;
int h[mxN];
long double a[mxN], b[mxN];
deque<array<int, 3>> dq;
long double eval(pair<int, int> a, int x) {
return (long double) a.second + (long double) sqrt(x - a.first);
}
int slope(pair<int, int> x, pair<int, int> y) {
if(x.second >= y.second) return n + 1;
int low = y.first, right = n;
while(low <= right) {
int mid = (low + right) / 2;
if(int(sqrt(mid - x.first)) + x.second >= int(sqrt(mid - y.first)) + y.second) {
low = mid + 1;
} else {
right = mid - 1;
}
}
return low;
}
void ins(pair<int, int> newLine) {
while(!dq.empty()) {
dq.back()[2] = slope({dq.back()[0], dq.back()[1]}, newLine);
if(dq.size() > 1 && dq[dq.size() - 2][2] >= dq.back()[2]) dq.pop_back();
else break ;
}
dq.push_back({newLine.first, newLine.second, n + 1});
}
void solve(long double dp[]) {
dq.clear();
for(int i = 1; i <= n; i ++) {
ins({i, h[i]});
while(!dq.empty() && dq.front()[2] < i) dq.pop_front();
dp[i] = eval({dq.front()[0], dq.front()[1]}, i);
}
}
int main() {
#define taskname ""
if (fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i ++) cin >> h[i];
solve(a);
reverse(h + 1, h + 1 + n);
solve(b);
reverse(h + 1, h + 1 + n);
reverse(b + 1, b + 1 + n);
for(int i = 1; i <= n; i ++) cout << (int)ceil(max(a[i], b[i])) - h[i] << "\n";
return 0;
}
Compilation message (stderr)
# | 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... |