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