Topic Link: 2216:[poi2011]lightning conductor
We first put p on the side of the equation and found
And then...... And then it turns out that this is a qaq of decision monotony.
Proof membrane popoqqq uncle: Orz Po elder sister
The first decision of life is monotonous get ...
For decision monotony, we can maintain a section of the element with a queue, each element in the queue has a decision interval, representing the number in this range can be transferred by him
Without a transfer, we will be the team head element of the interval left endpoint +1, if left endpoint > right end of the team out
Then consider the current decision point, if he is better than the team, then we may be able to add it to the queue, the comparison method is to use the last element A[n] Compare the size of the calculated p. Because the elements we maintain in the queue cover the entire [1,n] element, we will not be able to use the elements of the tail once the current element is superior to the team's tail.
And then further comparison, by the PO elder sister's proof we can know that light using a[n] comparison is not correct, so we compare the end of the team at the left end of the answer
Once I have the answer to the left end of the team, the end of the team is really useless, out of the team, know that there is a team tail of the left endpoint is not empty, then we in his decision-making interval to query to a position in this position so that the team at the end of the virtual, then all of the subsequent transfer by I this point to complete the queue
Code:
#include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <
Algorithm> using namespace std;
const int MAXN=1000000+10;
int a[maxn],n; struct Point{int l,r,p;}
Q[MAXN];
Double DP1[MAXN],DP2[MAXN];
Double cal (int x,int y) {return a[x]+sqrt (ABS (x-y)-a[y];}
int ask (point q,int x) {int l=q.l,r=q.r;
while (l<=r) {int mid= (L+R) >>1;
if (Cal (Q.p,mid) >cal (x,mid)) l=mid+1;
else r=mid-1;
}return l;
} void Get_dp (double *dp) {int h=1,t=0;
for (int i=1;i<=n;++i) {q[h].l++;
if (H<=T&&Q[H].L>Q[H].R) h++; if (h>t| | (Cal (I,n) >cal (q[t].p,n)))
{while (h<=t&&cal (I,Q[T].L) >=cal (Q[T].P,Q[T].L)) t--;
if (h>t) q[++t]= (point) {i,n,i};
else{int X=ask (q[t],i);
Q[t].r=x-1;
Q[++t]= (point) {x,n,i};
}}dp[i]=cal (Q[h].p,i);
int main () {scanf ("%d", &n);
for (int i=1;i<=n;++i) scanf ("%d", &a[i]);
GET_DP (DP1); for (int i=1;i<=n/2;++i) swap (a[i],a[n-I+1]);
GET_DP (DP2);
for (int i=1;i<=n;++i) printf ("%d\n", (int) (Ceil) (Max (dp1[i],dp2[n-i+1)));
}