Test instructions
There are n dragons that need to be killed.
Each dragon needs a knife with a fixed attack power of a and a knife to attack between [B,c].
Ask you at least how many knives you need at least
Ideas:
During training, there was no thought of using a tree array to query whether there were any knives in the interval.
Alas, it's too much food.
Let's sort all the intervals by the right end.
Every time you hit a knife, just mark the right end of the line.
1#include <bits/stdc++.h>2 #defineCL (b) memset (A,b,sizeof (a))3 #defineDebug (a) cerr<< #a << "= =" <<a<<endl4 using namespacestd;5typedefLong Longll;6typedef pair<int,int>PII;7 8 Const intmaxn=1e6+Ten;9 Ten inttree[maxn<<1]; One intvis[maxn<<1]; A Set<int>St; - - struct Point the { - intA; - PII q; - BOOL operator< (Constpoint& x)Const + { - returnq<x.q; + } A } PT[MAXN]; at - voidInit () - { - st.clear (); -CL (PT,0); -CL (tree,0); inCL (VIS,0); - } to + intLowbit (intx) - { the returnx& (-x); * } $ Panax Notoginseng voidAddintx) - { the while(x<MAXN) + { Atree[x]++; thex+=lowbit (x); + } - } $ $ intQueryintx) - { - intsum=0; the while(x>0) - {Wuyisum+=Tree[x]; thex-=lowbit (x); - } Wu returnsum; - } About $ intQueryintXinty) - { - returnQuery (y)-query (X-1); - } A + intMain () the { - intt,cas=1; $scanf"%d",&T); the init (); the while(t--) the { the init (); - intN; inscanf"%d",&n); the for(intI=0; i<n; i++) the { Aboutscanf"%d%d%d",&pt[i].a,&pt[i].q.second,&Pt[i].q.first); the } the for(intI=0; i<n; i++) the { + if(St.find (pt[i].a) = =st.end ()) - { the Add (pt[i].a);Bayi St.insert (PT[I].A); the } the } -Sort (pt,pt+n); - intans=st.size (); the //debug (ans); the for(intI=0; i<n; i++) the { the intsum=query (pt[i].q.second,pt[i].q.first); - //debug (sum); the if(pt[i].a>=pt[i].q.second&&pt[i].a<=Pt[i].q.first) the { thesum--;94 } the if(!sum) the { the Add (pt[i].q.first);98ans++; About } - }101printf"Case #%d:%d\n", cas++, ans);102 }103 return 0;104}/* the 106 4107 1108 7 6 8109 3 the 3 5111 6 the 3113 4 the 1 the 3 the 2117 4118 2119 5 - the121 122 */
Uvalive 6911Double Swords tree-like array