Advertisement
georgiy110802

Untitled

Jun 13th, 2021
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct Point
  6. {
  7.     int x, type, i;
  8. };
  9.  
  10. int main()
  11. {
  12.     ios::sync_with_stdio(0);
  13.     cin.tie(0);
  14.     int n, m;
  15.     cin >> n >> m;
  16.     vector<Point> points;
  17.     for(int i = 0; i < n; i++)
  18.     {
  19.         int a, b;
  20.         cin >> a >> b;
  21.         points.push_back({min(a, b), 0, -i - 1});
  22.         points.push_back({max(a, b), 2, -i - 1});
  23.     }
  24.     for(int i = 0; i < m; i++)
  25.     {
  26.         int x;
  27.         cin >> x;
  28.         points.push_back({x, 1, i});
  29.     }
  30.     sort(points.begin(), points.end(), [](Point l, Point r)
  31.     {
  32.         if(l.x != r.x)
  33.             return l.x < r.x;
  34.         else if(l.type != r.type)
  35.             return l.type < r.type;
  36.         else
  37.             return l.i < r.i;
  38.     });
  39.     vector<int> answer(m);
  40.     int count = 0;
  41.     for(auto i : points)
  42.     {
  43.         if(i.type == 0)
  44.             count++;
  45.         else if(i.type == 1)
  46.             answer[i.i] = count;
  47.         else
  48.             count--;
  49.     }
  50.     for(int i : answer)
  51.         cout << i << " ";
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement