Yale-Yale Training Day2 Time Machine machines

Source: Internet
Author: User

Main topic:

Give you two sets of intervals to ask for coverage problems.

For this problem we can sort the left endpoint of each interval, when enumerating nodes, when the left endpoint satisfies the requirement, is to make the right endpoint as close as possible to the right endpoint of the node, using map to optimize

The code is sent:

1#include <cstdio>2#include <algorithm>3#include <map>4 5 #defineFor (I, J, K) for (int i = j; I <= K; i++)6 #defineY Second7 8 9InlineintRead () {Ten     Charc =GetChar (); One      while(C <'0'|| C >'9') C =GetChar (); A     intx = C-'0'; -c =GetChar (); -      while(c <='9'&& C >='0') x = x *Ten+ C-'0', C =GetChar (); the     returnx; - } -  - Const intN =100010; +  - using namespacestd; +  AtypedefLong LongLL; at  -map<int, ll>M; -typedef map<int, ll>:: iterator it; -  - structnode{ -     intL, R, S; in  -     BOOL operator< (Constnode& B)Const{ to         returnL <B.L; +     } - }a[n], r[n]; the  *InlinevoidADD (intUints) { $     if(! M.count (U)) m[u] =s;Panax Notoginseng     ElseM[u] + =s; - } the  + intN, M; A  the voidCheck () { +     intj =1; -for (I,1, N) { $          while(J <= M && r[j].l <= a[i].l) ADD (R[J].R, R[J].S), + +J; $          while(A[I].S) { -It p =M.lower_bound (A[I].R); -             if(p = =M.end ()) { thePuts"No"); -                 return;Wuyi             } the             if(A[i].s < P-y) P-, Y-= a[i].s, A[i].s =0; -             ElseA[I].S-= P-y, M.erase (p); Wu         } -     } AboutPuts"Yes"); $ } -  - intMain () { -Freopen ("machine2.in","R", stdin); AFreopen ("Machine2.ans","W", stdout); +     intCase =Read (); the      while(case--){ - m.clear (); $n = Read (), M =Read (); thefor (I,1, n) a[i].l = Read (), A[I].R = Read (), A[I].S =Read (); thefor (I,1, m) r[i].l = Read (), R[I].R = Read (), R[I].S =Read (); theSort (A +1, A + n +1), sort (R +1, R + M +1); the check (); -     } in     return 0; the}

Yale-Yale Training Day2 Time Machine machines

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.