hkshakib

Untitled

Mar 20th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll mx = 1e5+10;
  5. vector<ll>RL[4*mx],RR[4*mx];
  6. ll arr[4*mx],brr[4*mx];
  7. set<ll>st;
  8. int n;
  9. void clr()
  10. {
  11. st.clear();
  12. for(int i=1;i<=2*n;i++)
  13. {
  14. RR[i].clear();
  15. RL[i].clear();
  16. arr[i]=0;
  17. brr[i]=0;
  18. }
  19. }
  20. int main()
  21. {
  22. int t,cnt=1;
  23. cin>>t;
  24. while(t--)
  25. {
  26. cin>>n;
  27. int l,r;
  28. clr();
  29. for(int i=1; i<=n; i++)
  30. {
  31. cin>>l>>r;
  32. RL[l].push_back(i);
  33. RR[r+1].push_back(i);
  34. brr[i]=0;
  35. }
  36. st.insert(0);
  37. int ans =0;
  38. for(int i=1; i<=2*n; i++)
  39. {
  40. for(auto &a: RL[i])
  41. st.insert(a);
  42. for(auto &a : RR[i])
  43. st.erase(a);
  44. arr[i]=*st.rbegin();
  45. brr[arr[i]]=1;
  46. }
  47. for(int i=1; i<=n; i++)
  48. {
  49. ans+=brr[i];
  50. }
  51. cout<<"Case "<<cnt++<<": ";
  52. cout<<ans<<endl;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment