#include <bits/stdc++.h>
#define li 500005
using namespace std;
int n,A[li],res[li];
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(optr,mid);i++){
if(A[i]+sqrt(abs(mid-i))>A[opt]+sqrt(abs(mid-opt))) opt=i;
}
res[mid]=max(res[mid],A[opt]-A[mid]+(int)ceil(sqrt(abs(mid-opt))));
solve(l,mid-1,optl,opt);
solve(mid+1,r,opt,optr);
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&A[i]);
solve(1,n,1,n);
reverse(A+1,A+n+1);
reverse(res+1,res+n+1);
solve(1,n,1,n);
reverse(A+1,A+n+1);
reverse(res+1,res+n+1);
for(int i=1;i<=n;i++) printf("%d\n",res[i]);
return 0;
}
Compilation message
pio.cpp: In function 'int main()':
pio.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
pio.cpp:18:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%d",&A[i]);
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
2412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
3108 KB |
Output is correct |
2 |
Correct |
36 ms |
3124 KB |
Output is correct |
3 |
Correct |
38 ms |
3772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
5064 KB |
Output is correct |
2 |
Correct |
63 ms |
5844 KB |
Output is correct |
3 |
Correct |
59 ms |
6952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
10372 KB |
Output is correct |
2 |
Correct |
143 ms |
12268 KB |
Output is correct |
3 |
Correct |
150 ms |
14240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
250 ms |
20424 KB |
Output is correct |
2 |
Correct |
219 ms |
21744 KB |
Output is correct |
3 |
Correct |
216 ms |
25944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
342 ms |
33320 KB |
Output is correct |
2 |
Correct |
329 ms |
35368 KB |
Output is correct |
3 |
Correct |
322 ms |
41204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
345 ms |
43564 KB |
Output is correct |
2 |
Correct |
316 ms |
47884 KB |
Output is correct |
3 |
Correct |
355 ms |
53784 KB |
Output is correct |