P3515 [POI2011]Lightning Conductor
May be converted to the formula: $ p> = a_j-a_i + sqrt (ij) (j <i) $
Where $ j> i $, and the formula can be inverted to give
Below a picture to prove it is to meet the decision-making monotony
The $ a_j + sqrt (ij) $ represented on a coordinate system
Apparently $ sqrt (ij) $ growth has slowed down
Curve A $ $ $ b $ after the curve is not more than the stand
Both directions monotonic points decision rule, they can take $ max $
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; int read(){ char c=getchar(); int x=0,f=1; while(c<'0'||c>'9') f=f&&(c!='-'),c=getchar(); while('0'<=c&&c<='9') x=x*10+c-48,c=getchar(); return f?x:-x; } #define N 500005 int n,a[N]; double p1[N],p2[N],w; void solve1(int l,int r,int dl,int dr){ int m=(l+r)/2,dm=dl; for(int i=dl;i<=m&&i<=dr;++i) if(p1[m]<(w=a[i]-a[m]+sqrt(m-i))) p1[m]=w,dm=i; if(l<m) solve1(l,m-1,dl,dm); if(m<r) solve1(m+1,r,dm,dr); } void solve2(int l,int r,int dl,int dr){ int m=(l+r)/2,dm=dr; for(int i=dr;i>=m&&i>=dl;--i) if(p2[m]<(w=a[i]-a[m]+sqrt(i-m))) p2[m]=w,dm=i; if(l<m) solve2(l,m-1,dl,dm); if(m<r) solve2(m+1,r,dm,dr); } int main(){ n=read(); for(int i=1;i<=n;++i) a[i]=read(); solve1(1,n,1,n); solve2(1,n,1,n); for(int i=1;i<=n;++i) printf("%d\n",(int)ceil(max(p1[i],p2[i]))); }