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;
int n, h[mxN], a[mxN], a1[mxN+1], a2[mxN+1];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i=0; i<n; ++i) {
cin >> h[i];
a1[i+1]=max(a[i]=h[i], a1[i]);
for(int j=0; i-j*j-1>=0; ++j)
a1[i+1]=max(++a[i-j*j-1], a1[i+1]);
}
for(int i=n-1; i>=0; --i) {
a2[i]=max(a[i]=h[i], a2[i+1]);
for(int j=0; i+j*j+1<=n-1; ++j)
a2[i]=max(++a[i+j*j+1], a2[i]);
}
for(int i=0; i<n; ++i)
cout << max(a1[i+1], a2[i])-h[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... |