Bzoj 1178 [Apio2009]convention Convention Center

Source: Internet
Author: User

That's a hard question! I'm a good cook!

Idea: For the most segments do not intersect, we can press the left endpoint sort after the greedy fetch. However, this topic requires that the selected segment is sorted after the ordinal is the smallest dictionary order.

So if we go from big to small with a serial number, then for the K-segment, we can still guarantee that the number of segments we can take

To the maximum, we consider the function Cal (L, R) to indicate the maximum number of segments L to R can be selected on the axis, the left and right end of the section K line is L, R, and the first left is L1, R1

The first one on the right is L2, R2, so the sufficient condition that K can put in is cal (R1 + 1, l2-1) = = cal (r1 + 1, l-1) + cal (R + 1, l2-1) + 1.

Then our problem becomes cal () how this function is implemented, we sort the original segment by the right endpoint, and then delete the segments that contain the other segments,

Then nx[I [0] = k is the first line that satisfies B[K].L > B[I].R, and then we multiply it to find out nx[I [j] indicates who is the 2^J segment on the right of I.

1#include <bits/stdc++.h>2 #defineLL Long Long3 #defineFi first4 #defineSe Second5 #defineMk Make_pair6 #definePII pair<int,int>7 #definePIII Pair<int, pair<int,int>>8 9 using namespacestd;Ten  One Const intn=200000+7; A Const intm=1e4+7; - Const intinf=0x3f3f3f3f; - ConstLL inf=0x3f3f3f3f3f3f3f3f; the Const intMod=1e9 +7; -  - intN, M, nx[n][ +], L[n], r[n]; -  + structLine { -     intL, R; +  ALine (int_l =0,int_r =0) { atL =_l; -R =_r; -     } -     BOOL operator< (ConstLine &AMP;RHS)Const { -         if(r = = RHS.R)returnL <RHS.L; -         returnR <RHS.R; in     } -  to } A[n], b[n]; +  - intCalintLintr) { the     intx = Lower_bound (L +1, L +1+ M, L)-L; *     if(X > M | | R[x] > R)return 0; $     intAns =1;Panax Notoginseng      for(inti = -; I >=0; i--) { -         if(Nx[x][i] && R[nx[x][i]] <=r) { theAns + =1<<i; +x =Nx[x][i]; A         } the     } +     returnans; - } $ intMain () { $  -scanf"%d", &n); -      for(inti =1; I <= N; i++) { thescanf"%d%d", &AMP;A[I].L, &A[I].R); -B[i] =A[i];Wuyi     } the  -Sort (b +1, B + n +1); Wu  -      for(inti =1; I <= N; i++) { About         if(!m | | b[i].l >b[m].l) $B[++M] =B[i]; -     } -  -      for(inti =1; I <= m; i++) AL[i] = B[I].L, r[i] =B[I].R; +  the      for(inti =1, j =1; I <= m; i++) { -          while(J <= M && b[j].l <= B[I].R) J + +; $         if(J <= m) nx[i][0] =J; the     } the  the      for(inti =1; I <= -; i++) { the          for(intj =1; J <= M; J + +) { -Nx[j][i] = nx[nx[j][i-1]][i-1]; in         } the     } the  About     intans = cal (-INF, INF); theprintf"%d\n", ans); the     Set<Line>St; the     intCNT =0; + St.insert (Line (INF, INF)); -St.insert (Line (-inf,-inf)); the Bayi      for(inti =1; I <= N; i++) { the         Set<line>::iterator it = St.lower_bound (A[i]), ITT = it; itt--; the         intL1 = ITT-r, r1 = a[i].l, L2 = a[i].r, r2 = it-l; -         if(L1 >= R1 | | L2 >= R2)Continue; -         if(Cal (L1 +1, R2-1) = = cal (L1 +1, R1-1) + cal (L2 +1, R2-1) +1) { the             if(++cnt = = ans) printf ("%d", i); the             Elseprintf"%d", i); the St.insert (A[i]); the         } -     } thePuts""); the     return 0; the }94 /* the */

Bzoj 1178 [Apio2009]convention Convention Center

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.