Advertisement
yeskendir_sultanov

Points in Segments

May 19th, 2025
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int testCnt;
  5.  
  6. void solve(int tc) {
  7.     cout << "Case " << tc << ":" << endl;
  8.     int n, q;
  9.     cin >> n >> q;
  10.     vector<pair<pair<int, int>, int>> b;
  11.     for (int i = 0; i < n; ++i) {
  12.         int l, r;
  13.         cin >> l >> r;
  14.         b.push_back({{l, 0}, i});
  15.         b.push_back({{r, 2}, i});
  16.     }
  17.     for (int i = 0; i < q; ++i) {
  18.         int x;
  19.         cin >> x;
  20.         b.push_back({{x, 1}, i});
  21.     }
  22.    
  23.     sort(b.begin(), b.end());
  24.     vector<int> ans(q);
  25.    
  26.     int cur = 0;
  27.    
  28.     for (auto x : b) {
  29.         int p = x.first.first;
  30.         int type = x.first.second;
  31.         int id = x.second;
  32.         if (type == 0) {
  33.             cur++;
  34.         } else if (type == 1) {
  35.             ans[id] = cur;
  36.         } else {
  37.             cur--;
  38.         }
  39.     }
  40.    
  41.     for (int i = 0; i < q; ++i) {
  42.         cout << ans[i] << endl;
  43.     }
  44. }
  45.  
  46. int main() {
  47.     ios_base::sync_with_stdio(false);
  48.     cin.tie(0); cout.tie(0);
  49.     cin >> testCnt;
  50.     for (int tc = 1; tc <= testCnt; ++tc) {
  51.         solve(tc);
  52.     }
  53.     return 0;
  54. }
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement