Advertisement
Guest User

JAPC1005 C++ Solution

a guest
May 2nd, 2021
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define LL int
  4. const LL MOD=1e9+7;
  5. // When something is important enough, you do it even if the odds are not in your favor.
  6.  
  7. int main(){
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(NULL);
  10. #ifdef somujena
  11. freopen("/home/somujena/competitive/input.txt", "r", stdin);
  12. freopen("/home/somujena/competitive/output.txt", "w", stdout);
  13. #endif
  14. // code goes here
  15. LL test=1; cin>>test;
  16. while(test--){
  17. LL n,q,i,j;cin>>n>>q;
  18. pair<LL,LL> a[n];
  19. for(i = 0; i < n; i++) cin>>a[i].first>>a[i].second,a[i].second*=-1;
  20. sort(a,a+n);
  21. reverse(a,a+n);
  22. for(i = 0; i < n; i++) a[i].second*=-1;
  23. std::vector<LL> v;
  24. set<pair<LL,LL> > s;
  25. LL m[n+4];
  26. for(i = 0; i < n+4; i++) m[i]=0;
  27. LL r=0;
  28. for(i = 0; i < n; i++){
  29. if(i>0&&a[i]==a[i-1]){
  30. m[*v.rbegin()]++;
  31. r++;
  32. }
  33. else{
  34. s.insert(a[i]);
  35. r++;
  36. v.push_back(r);
  37. m[*v.rbegin()]++;
  38. }
  39. }
  40. while(q--){
  41. LL r,i,j;cin>>r;
  42. LL in=upper_bound(v.begin(), v.end(),r)-v.begin();in--;
  43. cout<<m[v[in]]<<endl;
  44. }
  45.  
  46.  
  47. }
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement