DP can be stacked uoj205 "APIO2016" Fireworks

Source: Internet
Author: User

http://uoj.ac/problem/205

That's a good question.
Set state \ (f[id][t]\) is the minimum cost for all points in a subtree to be completed in \ (t\) time
Through observation, we can find
\ (f\) value forms a lower convex packet
Take minimum value in Interval \ ([L, r]\)
Consider the transfer of violence
Update parent Node Answer
and violent merging on a convex hull
Complexity \ (O ((n + m) ^ 2) \)

After the transfer equation is listed
The slope of \ (x\) is \ ( -1, 0, 1\), respectively
The discovery is essentially an upward translation of a convex package
Add two more inflection points (the inflection point on the convex hull)

It is found that the pattern of the convex hull is only related to the number of inflection points
The slope of each inflection point is \ (+1\)
We want to maintain the convex hull of \ (k <= 0\)
is to delete all the inflection points of the slope greater than \ (0\)

\ (f[rt]\) convex hull with \ (y\) axis intersection known
For \ (\sum\) Benquan
and the position of X can be reached by the number of inflection points
So we can maintain the inflection point.

So how do we merge?
With a big pile of sticks.
Each time the \ (k\) greater than 0 of the inflection point sieve off
At this point, the right slope of the convex hull is the number of his children.
So just delete the kids and a few inflection points.
And then add two more to it.

Complexity \ (O ((n + m) log (n + m))

#include <bits/stdc++.h>#define INT Long Long#define FO (i, n) for (int i = 1; I <= (n); i + +)#define OUT (x) cerr << #x << "=" << x << "\N "#define TYPE (x) __typeof ((x). Begin ())#define foreach (it, x) for (type (x) it = (x). Begin (); it! = (x). end (); + + it)using namespaceStd//By PianoTemplate<TypeNameTp>inline voidREAD (TP &x) {x =0;Charc = GetChar ();BOOLf =0; for(; c <' 0 '|| C >' 9 '; F |= (c = ='-'), C = GetChar ()); for(; C >=' 0 '&& C <=' 9 '; x = (x <<3) + (x <<1) + C-' 0 ', C = GetChar ());if(f) x =-X.;}Template<TypeNameTp>inline voidARR (TP *a,intN) { for(inti =1; I <= N; i + +) cout << A[i] <<" "; Puts"");}Const intN =6e5+233;intN, M, Fa[n], w[n], sz[n], ans =0;intKey[n], fix[n], sa =0, L[n], r[n], rt[n];inline intnwintVal) {+ + sa; L[SA] = R[sa] =0;  KEY[SA] = val; FIX[SA] = rand ();returnSA;}inline intMakeintXintY) {if(!x | |!y)returnx | Yif(Key[x] < key[y]) swap (x, y);if(Fix[x] < fix[y]) R[X] = make (r[x], y);ElseL[X] = make (l[x], y);returnx;}inline voidPopintx) {Rt[x] = make (L[rt[x]], r[rt[x]);}inline voidDfsintx) {if(!x)return; cout << Key[x] <<" "<< x <<"\ n"; DFS (l[x]); DFS (R[x]);} Mainvoid) {Srand (20021214); Read (n); Read (m);intAll = n + M; for(inti =2; I <= all;    i + +) {Read (fa[i]); Read (W[i]);    Ans + = w[i];  Sz[fa[i]] + +; } for(inti = ALL; I >=2; I--) {intL =0, r =0;if(Sz[i]) { while(--sz[i]) pop (i); r = Key[rt[i]];      Pop (i); L = key[rt[i]];    Pop (i);    } L = NW (l + w[i]);    R = NW (r + w[i]);    Rt[i] = make (Rt[i], make (L, R));  Rt[fa[i]] = make (Rt[fa[i]], rt[i]); } while(sz[1]--) Pop (1); while(rt[1]) {ans-= key[rt[1]]; Pop1); } cout << ans <<"\ n";}

DP can be stacked uoj205 "APIO2016" Fireworks

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.