#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
const int inf=1e9;
int n;
int h[N],dp[N];
void solve(int l,int r,int optl,int optr){
if(l>r)return;
int mid=(l+r)/2;
int opt=optl;
for(int i=optl;i<=min(mid,optr);i++)if(h[i]+sqrt(mid-i)>h[opt]+sqrt(mid-opt))opt=i;
dp[mid]=max(dp[mid],(int)ceil(h[opt]-h[mid]+sqrt(mid-opt)));
solve(l,mid-1,optl,opt);
solve(mid+1,r,opt,optr);
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n;
for(int i=1;i<=n;i++)cin >> h[i];
for(int t=0;t<2;t++){
solve(1,n,1,n);
reverse(h+1,h+n+1);
reverse(dp+1,dp+n+1);
}
for(int i=1;i<=n;i++)cout << dp[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
2956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
2904 KB |
Output is correct |
2 |
Correct |
19 ms |
2956 KB |
Output is correct |
3 |
Correct |
20 ms |
3160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3152 KB |
Output is correct |
2 |
Correct |
32 ms |
3164 KB |
Output is correct |
3 |
Correct |
32 ms |
3564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
4220 KB |
Output is correct |
2 |
Correct |
81 ms |
4056 KB |
Output is correct |
3 |
Correct |
73 ms |
4708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
7076 KB |
Output is correct |
2 |
Correct |
120 ms |
4944 KB |
Output is correct |
3 |
Correct |
117 ms |
7252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
9208 KB |
Output is correct |
2 |
Correct |
173 ms |
6144 KB |
Output is correct |
3 |
Correct |
165 ms |
9300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
6884 KB |
Output is correct |
2 |
Correct |
175 ms |
6228 KB |
Output is correct |
3 |
Correct |
168 ms |
9184 KB |
Output is correct |