BZOJ2216 [poi2011]lightning Conductor

Source: Internet
Author: User

Orz YDC: "This is the first non-slope optimized 1d1d I've seen ..."

Say YDC god Ben that the monotony queue is not optimized BAA? 、、、 've been kneeling.

Orz of decision Monotonicity

1 /**************************************************************2 problem:22163 User:rausen4 language:c++5 result:accepted6 time:4128 Ms7 memory:16432 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <cmath> A#include <algorithm> -   - using namespacestd; thetypedefDoubleLF; - Const intN =500005; -   - structData { +     intL, R, p; - data () {} +Dataint_l,intArrint_p): L (_l), R (_r), p (_p) {} A }q[n]; at   - intN, A[n]; - LF F[n], g[n]; -   -InlineintRead () { -     intx =0, SGN =1; in     CharCH =GetChar (); -      while(Ch <'0'||'9'<ch) { to         if(ch = ='-') SGN =-1; +CH =GetChar (); -     } the      while('0'<= CH && Ch <='9') { *x = x *Ten+ CH-'0'; $CH =GetChar ();Panax Notoginseng     } -     returnSGN *x; the } +   AInline LF Calc (intJinti) { the     returnA[J]-a[i] + sqrt (ABS (i-j)); + } -   $ intFind (Data T,intx) { $     intL = t.l, r =T.R, mid; -      while(L <=r) { -MID = L + R >>1; the         if(Calc (T.P, mid) >Calc (x, mid)) -L = mid +1;Wuyi         ElseR = Mid-1; the     } -     returnl; Wu } -   About voidDP (LF *F) { $      for(inti =1, h =1, t =0, TMP; I <= N; ++i) { -++Q[H].L; -         if(H <= t && q[h].r < Q[H].L) + +h; -         if(H > T | | calc (i, N) >Calc (Q[T].P, N)) { A              while(H <= t && Calc (Q[T].P, Q[T].L) <Calc (i, Q[T].L)) +--T; the             if(H > t) q[++t] =data (i, n, i); -             Else { $TMP =find (Q[t], i); theQ[T].R = tmp-1; theQ[++T] =data (TMP, n, i); the             } the         } -F[i] =Calc (q[h].p, i); in     } the } the   About intMain () { the     inti; then =read (); the      for(i =1; I <= N; ++i) +A[i] =read (); - DP (f); theReverse (A +1, A + n +1);Bayi DP (g); the      for(i =1; I <= N; ++i) theprintf"%d\n", (int) Ceil (Max (F[i], g[n-i +1]))); -     return 0; - } the 
View Code

BZOJ2216 [poi2011]lightning Conductor

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.