Bzoj:[poi2011]lightning Conductor: Decision Monotonicity optimization DP detailed __oi

Source: Internet
Author: User

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&LT;=T&AMP;&AMP;Q[H].L&GT;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)));
 }




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.