fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7. int q ; cin>>q; int p ; cin>>p;
  8. vector<vector<int>>query(q,vector<int>(2,0));
  9. vector<pair<int,int>>bounds;
  10. for(int i = 0 ; i<q;i++){
  11. int l ; int r ;
  12. cin>>l>>r;
  13. query[i][0]=l; query[i][1]=r;
  14. bounds.push_back({l,0});
  15. bounds.push_back({r,2});
  16. }
  17. for(int i = 0 ; i<p;i++){
  18. int point ; cin>>point;
  19. bounds.push_back({point,1});
  20. }
  21.  
  22. sort(bounds.begin(),bounds.end());
  23.  
  24. int n = bounds.size();
  25. map<int,int>prefix;
  26. int c=0;
  27. for(int i = 0 ; i<n;i++){
  28. if(bounds[i].second==0) {
  29. c=c+1;
  30.  
  31. }
  32. else if (bounds[i].second ==1){
  33. prefix[bounds[i].first]=c;
  34. cout<<c<<" ";
  35. }
  36. else{
  37.  
  38. c=c-1;
  39. }
  40. }
  41.  
  42.  
  43.  
  44.  
  45. // your code goes here
  46. return 0;
  47. }
Success #stdin #stdout 0.01s 5320KB
stdin
5 3
1 5
2 7 
1 4 
5 10 
3 5 
1 6 8 
stdout
2 2 1