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>
#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 (stderr)
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 |
---|
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... |