Leave pit
Why the slope optimization of other people's home is not the same as mine!
Why does the slope have to become positive ...
Why do you have to push the equation?
Why can't you just do it?
Why don't you get rid of 0 and go to WA?
Why does the cross-product go to 0?
WoC.
1#include <cstdio>2#include <cstring>3#include <cstdlib>4#include <algorithm>5#include <iostream>6 7 using namespacestd;8 9 voidSetio (Const string&s) {TenFreopen ((S +". in"). C_STR (),"R", stdin); OneFreopen ((S +". out"). C_STR (),"W", stdout); A } -Template<typename q> Q Read (q&x) { - Static Charc, F; the for(f =0; c = GetChar (),!isdigit (c); )if(c = ='-') F =1; - for(x =0; IsDigit (c); c = GetChar ()) x = x *Ten+ C-'0'; - if(f) x =-x; - returnx; + } -Template<typename q>Q Read () { + StaticQ x; Read (x);returnx; A } at -typedefLong LongLL; - Const intN =100000+Ten; - -LL Sqr (Constll&x) { - returnX *x; in } - to LL F[n], g[n], sum[n]; + intQ[n]; - theLL Up (inti) { * returnG[i]-Sqr (Sum[i]); $ }Panax Notoginseng -LL Up (intIintj) { the returnUp (j)-Up (i); + } A theLL Down (intIintj) {//>= 0 + returnSUM[J]-Sum[i]; - } $ $ DoubleSlopeintIintj) { - returnUp (I, j)/(Double) Down (i, j); - } the intN; - Wuyi structNode { the LL x, y; - Node () {} WuNode (Constll& x,Constll&y): x (x), Y (y) {} -Nodeoperator- (Constnode& RHS)Const { About returnNode (x-rhs.x, Y-rhs.y); $ } - }p[n]; - -LL Cross (Constnode& A,Constnode&b) { A returna.x * b.y-b.x *a.y; + } the - voiddpintSt) { $ intL =0, R =0; theq[r++] =St; the for(inti = st +1; I <= N; i++) { the //while (L + 1 < R &&-sum[i] < slope (Q[l], q[l + 1])) l++; the //while (L + 1 < R &&-sum[i] * Down (q[l], q[l + 1]) < up (Q[l], q[l + 1])) l++; - while(L +1< R && Cross (Node (1,-sum[i]), P[l +1]-p[l]) >=0) l++; in intj =Q[l]; theF[i] = G[j] + sum[j] * (sum[i)-sum[j]); the //While (L + 1 < R && Slope (q[r-2], q[r-1]) < slope (Q[r-2], i)) r--; About //While (L + 1 < R && up (Q[r-2], q[r-1]) * Down (q[r-2], i) < up (Q[r-2], i) * Down (q[r-2], Q[R-1]) r--; the Node u (sum[i], up (i)); the while(L +1< R && Cross (P[r-1]-P[r-2], U-p[r-2]) >=0) r--; theQ[r] = i, p[r++] =u; + } - for(inti = st +1; I <= N; i++) G[i] =F[i]; the }Bayi the intMain () { the #ifdef DEBUG -Freopen ("In.txt","R", stdin); -Freopen ("OUT.txt","W", stdout); the #endif the the read (n); the intK = read<int>(); - the for(inti =1; I <= N; i++) { the intx = read<int>(); the if(!x) I--, n--;94 ElseSum[i] = sum[i-1] +x; the //Sum[i] = sum[i-1] + read<int> (); the } the 98 for(inti =1; I <= K; i++) DP (i); About -printf"%lld\n", G[n]);101 102 return 0;103}View Code
bzoj3675: [Apio2014] Sequence Segmentation