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