Topic Connection: BZOJ-3218
Problem analysis
The topic requires that n Dianran be black or white, then we can convert to a minimal cut model.
We stipulate that a point I finally belongs to the S-set expression dyed black, which belongs to the T-set to be dyed white, then for each point I will have the edge (S, I, B[i]) and (I, T, W[i]).
Thus, if a point belongs to the S-set, it is necessary to cut off the side connected to T, which is equivalent to losing the income dyed white.
Let's consider the "strange point", the condition that a point I becomes strange point is: I is black and there is a white dot J satisfies J < i && L[i] <= a[j] <= r[i].
For this, we can add a point n + i to each point I, a hyphen (i, n + i, p[i]), for each qualifying J, a hyphen (n + i, J, INF).
Thus, as long as J is white, then J is connected to T, and n + i is bound to T, and if I is connected to S, it must be cut off (i---n + i) value of p[i] edge.
However, such a number of edges can reach the n^2 level, and it is not possible to pass all the data.
We can consider optimizing the connection edge of the network stream with the segment tree.
We build a tree of weights segment (for all L, R, A discretization will save time and space), from each J corresponding to the a[j] node to the J-connected INF Edge, from the line tree node to the node's son node to the edge of the INF, for each I, then the line tree to find the corresponding [L[i], R[i] ] interval, from n + I to the nodes that make up these intervals are connected to the INF edge.
However, we have not considered the J < I limit, then the use of a durable line tree can be used.
One thing to note is that for the I position, insert a[i], is based on the i-1 version of the line segment tree, if found in the I-1 version of the segment tree has a weight of a[i] node, then from the I version of the A[i] single point of the Segment tree node (set to now) to I- The Segment tree node (set to last) Edge (now, last, INF) in the 1 segment tree that represents the A[i] single point.
Code
#include <iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<map>using namespacestd;Const intMAXN = the+5, Maxnode =100000+5, MAXM =200000+5, INF =999999999; Map<int,int>M;intN, Top, Tot, S, T, HN, Index, Ans;intA[MAXN], B[MAXN], W[MAXN], L[MAXN], R[MAXN], PI[MAXN], ARR[MAXN *3];intROOT[MAXN], son[maxnode][2], D[maxnode], Num[maxnode]; structedge{intu, V, W; Edge*next, *Other ;} E[MAXM*2], *p = E, *point[maxnode], *Last[maxnode]; inlinevoidAddedge (intXintYintz) {Edge*q = ++p; ++Q; Pu = x; P-v = y; P-W =Z; PNext = Point[x]; POINT[X] = P; P, other =Q; Qu = y; Q-v = x; Q-W =0; QNext = Point[y]; Point[y] = Q; Q-and other =P;} voidInsert (int&x,intLt,intSintTintPosintIDX) { if(x = =0) x = + +Index; if(s = =t) {Addedge (Tot+x, IDX, INF); if(Lt) Addedge (tot + x, tot +Lt, INF); return; } intm = (s + t) >>1; if(Pos <=m) {son[x][1] = son[lt][1]; Insert (son[x][0], son[lt][0], S, M, Pos, IDX); } Else{son[x][0] = son[lt][0]; Insert (son[x][1], son[lt][1], M +1, T, Pos, IDX); } if(son[x][0]) Addedge (tot + x, tot + son[x][0], INF); if(son[x][1]) Addedge (tot + x, tot + son[x][1], INF);} voidLink (intXintSintTintLintRintIDX) { if(l <= s && R >=t) {Addedge (n+ IDX, Tot +x, INF); return; } intm = (s + t) >>1; if(son[x][0] && l <= m) Link (son[x][0], S, M, L, R, IDX); if(son[x][1] && r >= m +1) Link (son[x][1], M +1, T, L, R, IDX);} InlineintGminintAintb) {returnA < b?a:b;} intDFS (intNow,intFlow) { if(now = = T)returnFlow; intRET =0; for(Edge *j = Last[now]; j; j = JNext) { if(J, W && d[now] = = D[j V] +1) { intp = DFS (J-V, Gmin (J-W, Flow-ret)); JW-= p; J, Other, w + = p; RET + =p; if(ret = = Flow)returnret; } } if(D[s] >= Tot)returnret; if(--num[d[now]] = =0) D[s] =Tot; ++num[++D[now]]; Last[now]=Point[now]; returnret;} intMain () {scanf ("%d", &N); Top=0; for(inti =1; I <= N; ++i) {scanf ("%d%d%d%d%d%d", &a[i], &b[i], &w[i], &l[i], &r[i], &Pi[i]); arr[++top] = A[i]; Arr[++top] = L[i]; Arr[++top] =R[i]; } sort (Arr+1, ARR + Top +1); HN=0; M.clear (); for(inti =1; I <= Top; ++i) {if(I! =1&& Arr[i] = = Arr[i-1])Continue; M[arr[i]]= ++HN; } for(inti =1; I <= N; ++i) {A[i]=M[a[i]]; L[i]= M[l[i]]; R[i] =M[r[i]]; } memset (Root,0,sizeof(Root)); S= n *2+1; T = n *2+2; Tot= n *2+2; Index=0; Ans=0; for(inti =1; I <= N; ++i) {Addedge (S, I, b[i]); Addedge (i, T, W[i]); Addedge (i, N+I, pi[i]); Ans+ = B[i] +W[i]; } for(inti =1; I <= N; ++i) {if(I >1) Link (Root[i-1],1, HN, L[i], r[i], i); Insert (Root[i], root[i-1],1, HN, a[i], i); } Tot= Tot +Index; memset (d,0,sizeof(d)); memset (Num,0,sizeof(Num)); num[0] =Tot; for(inti =1; I <= Tot; ++i) Last[i] =Point[i]; while(D[s] < Tot) Ans-=DFS (S, INF); printf ("%d\n", Ans); return 0;}
[Bzoj 3218] A + B Problem "can persist segment tree + network Flow"