Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <vector>
- #include <fstream>
- #include <cmath>
- #include <climits>
- #include <string>
- #include <set>
- #include <algorithm>
- #include <iomanip>
- #include <stack>
- #include <queue>
- #include <cstdio>
- using namespace std;
- #define ll long long
- #define all(x) x.begin(), x.end()
- #define event Event
- struct event {
- ll x;
- ll type;
- ll id;
- bool operator<(const event &a) const {
- if (x != a.x)
- return x < a.x;
- return type < a.type;
- }
- };
- void solve() {
- ll n, m;
- cin >> n >> m;
- vector<event> vc;
- for (int i = 0; i < n; ++i) {
- ll a, b;
- cin >> a >> b;
- if (a > b)
- swap(a, b);
- vc.push_back({a, 0});
- vc.push_back({b, 2});
- }
- vector<ll> ans(m);
- for (int i = 0; i < m; ++i) {
- ll x;
- cin >> x;
- vc.push_back({x, 1, i});
- }
- sort(all(vc));
- // for (auto i: vc) {
- // cout << i.type << " " << i.x << '\n';
- // }
- ll cur = 0;
- for (auto i : vc) {
- if (i.type == 0) {
- cur++;
- }
- else if (i.type == 2) {
- cur--;
- }
- else {
- if (cur != 0) {
- ans[i.id] += cur;
- }
- }
- }
- for (int i = 0; i < m; ++i) {
- cout << ans[i] << " ";
- }
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0), cout.tie(0);
- if (getenv("INOUT")) {
- freopen("input.in", "r", stdin);
- freopen("input.out", "w", stdout);
- }
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement