ARC076 F exhausted? Hall theorem + segment tree Scan line

Source: Internet
Author: User

~ ~ ~ Noodles ~ ~ ~

Main topic:

There are n people, M seats, everyone can match the seat is [1, Li] | | [Ri, M], someone may not need to match a seat (by default) and ask at least how many people cannot be satisfied.

Exercises

First we can see that this is a binary graph match, according to the Hall theorem, we only need to ask for Max (the size of the subset of people-the chosen person can choose the size of the seat set).

However, the complexity of the enumerator is too high, so consider enumerating the seat sets, because each person's constituency is a prefix or suffix, so to express a legitimate seating set, we only need the right-most Li and the leftmost RI for everyone.

  

So this time to make it as close to Max as possible, add all the people in the range that are not more than our current enumeration.

You can use the scan lines to find the values corresponding to all l in each R.

  

1#include <bits/stdc++.h>2 using namespacestd;3 #defineR Register int4 #defineAC 4001005 #defineAC 1601000//Error!!! The data range is 2 00000, not the 1 start!!! 6 7 intN, m, ans =-Int_max, W;8 intHead[ac], Next[ac], Date[ac], tot;9 intTree[ac], Lazy[ac], L[ac], R[ac], L_[ac], R_[ac];Ten  OneInlineintRead () A { -     intx =0;Charc =GetChar (); -      while(C >'9'|| C <'0') C =GetChar (); the      while(c >='0'&& C <='9') x = x *Ten+ C-'0', C =GetChar (); -     returnx; - } -  +InlinevoidAddintFintW) - { +Date[++tot] = W, next[tot] = Head[f], head[f] =tot; A } at  -InlinevoidUpmax (int&a,intb) - { -     if(b > A) a =b; - } -  in voidPre () - { ton = Read (), M =read (); +      for(R i =1; I <= N; i + +)  -L_[i] = Read (), r_[i] =read (), add (R_[i], i); the } *  $InlinevoidPushdown (intx)Panax Notoginseng { -     if(Lazy[x]) the     { +         intLL = x *2, rr = ll +1; ALAZY[LL] + = Lazy[x], LAZY[RR] + =Lazy[x]; theTREE[LL] + = Lazy[x], TREE[RR] + + lazy[x];//This is because it is + =, so you must use lazy[x], otherwise you will lazy[ll] some of the things to repeat statistics +LAZY[X] =0;//Finally, we emptied the!!!!!!!!!!.  -}//Error!!! is the interval plus, not the assignment, cannot be directly covered, to + = $ } $  -InlinevoidUpdateintx) - { theTREE[X] = max (TREE[X *2], Tree[x *2+1]);  - }Wuyi  the voidBuildintXintllintRR) - { WuL[X] = ll, r[x] =RR; -     if(LL = =RR) About     { $TREE[X] =-ll +1; -         return ; -     } -     intMID = (ll + RR) >>1; ABuild (X *2, LL, mid); +Build (X *2+1, Mid +1, RR); the update (x); - } $  the voidChangeintXintllintRR) the { the pushdown (x); the     if(L[x] = = ll && R[x] = =RR) -     { inLAZY[X] + = W, tree[x] + =W; the         return ; the     } About     intMID = (L[x] + r[x]) >>1; the     if(RR <= mid) change (x *2, LL, RR); the     Else if(ll > Mid) change (x *2+1, LL, RR); the     Else +     { -Change (x *2, LL, mid); theChange (x *2+1, Mid +1, RR);Bayi     } the update (x); the } -      - voidFindintXintllintRR) the { the pushdown (x); the     if(L[x] = = ll && R[x] = =RR) the     { - Upmax (ans, tree[x]); the         return ;  the     } the     intMID = (L[x] + r[x]) >>1;94     if(RR <= mid) find (x *2, LL, RR); the     Else if(ll > Mid) find (x *2+1, LL, RR); the     ElseFind (X *2, LL, mid), find (x *2+1, Mid +1, RR);//this is to take Max ,,,, the }98  About voidWork () - {101     intNow ;102ans = n-m;//Case of R = 0103      for(R i = head[m +1]; I i =Next[i])104     { thenow = Date[i], W =1;106Change1, L_[now] +1, M +1);107         //Find (1, 4, 4);108     }109     //Find (1, 4, 4); theUpmax (ans, tree[1]);111      for(R i = m; i;--i) the     {113W =-1; theChange1,1, i +1); the          for(R j = head[i]; j; j =Next[j]) the         {117now = Date[j], W =1;118Change1, L_[now] +1, i +1);119         } -Find1,1, i +1);//The left end is not legal at the back.121     }122printf"%d\n", ans);123 }124  the intMain ()126 {127Freopen ("in.in","R", stdin); - pre ();129Build1,1, M +1);//one more to represent the left 0 of the situation . theWork ();//ri Max can actually go to m+1 ...131 fclose (stdin); the     return 0;133}
View Code

ARC076 F exhausted? Hall theorem + segment tree Scan line

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.