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,1});
  16. }
  17.  
  18. sort(bounds.begin(),bounds.end());
  19.  
  20. int n = bounds.size();
  21. map<int,int>prefix;
  22. for(int i = 0 ; i<n;i++){
  23. if(bounds[i].second==0) prefix[bounds[i].first]++;
  24. else{
  25. prefix[bounds[i].first]--;
  26. }
  27. }
  28. for(int i = 0 ; i<p;i++){
  29. int point ; cin>>point;
  30. int ans=0;
  31. for(auto b : prefix){
  32. if(b.first<=point) ans+=b.second;
  33. else{
  34. break;
  35. }
  36. }
  37. cout<<ans;
  38. }
  39.  
  40.  
  41.  
  42. // your code goes here
  43. return 0;
  44. }
Success #stdin #stdout 0.01s 5320KB
stdin
5 3
1 5
2 7 
1 4 
5 10 
3 5 
1 2 8 


stdout
231