#include <bits/stdc++.h>
using namespace std;
long long dp[500001];
long long arr[500001];
void dc(int l,int r,int optl,int optr){
if(l>r)return ;
int mid = (l+r)/2;
long long best = optl;
for(int cut = optl;cut<=min(mid,optr);cut++){
if(arr[best]+sqrt(abs(mid-best))<arr[cut]+sqrt(abs(mid-cut))){
best = cut;
}
}
dp[mid]=max(dp[mid],arr[best]+(long long)ceil(sqrt(abs(mid-best))));
int opt = best;
dc(l,mid-1,optl,opt);
dc(mid+1,r,opt,optr);
}
int main(){
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
for(int i = 1;i<=n;i++){
cin>>arr[i];
}
for(int i = 0;i<=n;i++)dp[i] = 0;
dc(1,n,0,n-1);
reverse(arr+1,arr+n+1);
reverse(dp+1,dp+n+1);
dc(1,n,0,n-1);
reverse(dp+1,dp+n+1);
reverse(arr+1,arr+n+1);
for(int i = 1;i<=n;i++){
cout<<dp[i]-arr[i]<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
1584 KB |
Output is correct |
2 |
Incorrect |
27 ms |
1484 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
2188 KB |
Output is correct |
2 |
Correct |
63 ms |
2116 KB |
Output is correct |
3 |
Correct |
53 ms |
2716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
4932 KB |
Output is correct |
2 |
Correct |
137 ms |
4692 KB |
Output is correct |
3 |
Correct |
120 ms |
5452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
9200 KB |
Output is correct |
2 |
Correct |
233 ms |
7196 KB |
Output is correct |
3 |
Correct |
201 ms |
9204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
343 ms |
12972 KB |
Output is correct |
2 |
Correct |
326 ms |
10316 KB |
Output is correct |
3 |
Correct |
269 ms |
13088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
336 ms |
10788 KB |
Output is correct |
2 |
Correct |
316 ms |
10060 KB |
Output is correct |
3 |
Correct |
274 ms |
13100 KB |
Output is correct |