Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct Point
- {
- int x, type, i;
- };
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- int n, m;
- cin >> n >> m;
- vector<Point> points;
- for(int i = 0; i < n; i++)
- {
- int a, b;
- cin >> a >> b;
- points.push_back({min(a, b), 0, -i - 1});
- points.push_back({max(a, b), 2, -i - 1});
- }
- for(int i = 0; i < m; i++)
- {
- int x;
- cin >> x;
- points.push_back({x, 1, i});
- }
- sort(points.begin(), points.end(), [](Point l, Point r)
- {
- if(l.x != r.x)
- return l.x < r.x;
- else if(l.type != r.type)
- return l.type < r.type;
- else
- return l.i < r.i;
- });
- vector<int> answer(m);
- int count = 0;
- for(auto i : points)
- {
- if(i.type == 0)
- count++;
- else if(i.type == 1)
- answer[i.i] = count;
- else
- count--;
- }
- for(int i : answer)
- cout << i << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement