#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> p2;
const int N=5e5+5;
const int inf=1e9;
int n;
int h[N],dp[N];
void solvel(int l,int r,int optl,int optr){
if(l>r)return;
int mid=(l+r)/2;
p2 res(-inf,0);
for(int i=optl;i<=min(mid,optr);i++)res=max(res,p2(h[i]+(int)ceil(sqrt(mid-i))-h[mid],-i));
dp[mid]=max(dp[mid],res.first);
int opt=-res.second;
solvel(l,mid-1,optl,opt);
solvel(mid+1,r,opt,optr);
}
void solver(int l,int r,int optl,int optr){
if(l>r)return;
int mid=(l+r)/2;
p2 res(-inf,0);
for(int i=max(mid,optl);i<=optr;i++)res=max(res,p2(h[i]+(int)ceil(sqrt(i-mid))-h[mid],i));
dp[mid]=max(dp[mid],res.first);
int opt=res.second;
solver(l,mid-1,optl,opt);
solver(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];
solvel(1,n,1,n);
solver(1,n,1,n);
for(int i=1;i<=n;i++)cout << dp[i] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3024 KB |
Output is correct |
2 |
Correct |
15 ms |
2908 KB |
Output is correct |
3 |
Incorrect |
17 ms |
3164 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
3164 KB |
Output is correct |
2 |
Correct |
36 ms |
3056 KB |
Output is correct |
3 |
Incorrect |
26 ms |
3676 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
4272 KB |
Output is correct |
2 |
Correct |
82 ms |
4176 KB |
Output is correct |
3 |
Incorrect |
69 ms |
4692 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
7096 KB |
Output is correct |
2 |
Correct |
137 ms |
5108 KB |
Output is correct |
3 |
Incorrect |
97 ms |
7252 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
9296 KB |
Output is correct |
2 |
Correct |
204 ms |
6144 KB |
Output is correct |
3 |
Incorrect |
138 ms |
9468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
151 ms |
6696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |