Advertisement
JolyCoder

Untitled

Jul 23rd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <fstream>
  5. #include <cmath>
  6. #include <climits>
  7. #include <string>
  8. #include <set>
  9. #include <algorithm>
  10. #include <iomanip>
  11. #include <stack>
  12. #include <queue>
  13. #include <cstdio>
  14.  
  15. using namespace std;
  16.  
  17. #define ll long long
  18. #define all(x) x.begin(), x.end()
  19. #define event Event
  20.  
  21. struct event {
  22.     ll x;
  23.     ll type;
  24.     ll id;
  25.  
  26.     bool operator<(const event &a) const {
  27.         if (x != a.x)
  28.             return x < a.x;
  29.         return type < a.type;
  30.     }
  31. };
  32.  
  33. void solve() {
  34.     ll n, m;
  35.     cin >> n >> m;
  36.     vector<event> vc;
  37.     for (int i = 0; i < n; ++i) {
  38.         ll a, b;
  39.         cin >> a >> b;
  40.         if (a > b)
  41.             swap(a, b);
  42.         vc.push_back({a, 0});
  43.         vc.push_back({b, 2});
  44.     }
  45.     vector<ll> ans(m);
  46.     for (int i = 0; i < m; ++i) {
  47.         ll x;
  48.         cin >> x;
  49.         vc.push_back({x, 1, i});
  50.     }
  51.     sort(all(vc));
  52. //    for (auto i: vc) {
  53. //        cout << i.type << " " << i.x << '\n';
  54. //    }
  55.     ll cur = 0;
  56.     for (auto i : vc) {
  57.         if (i.type == 0) {
  58.             cur++;
  59.         }
  60.         else if (i.type == 2) {
  61.             cur--;
  62.         }
  63.         else {
  64.             if (cur != 0) {
  65.                 ans[i.id] += cur;
  66.             }
  67.         }
  68.  
  69.     }
  70.     for (int i = 0; i < m; ++i) {
  71.         cout << ans[i] << " ";
  72.     }
  73. }
  74.  
  75. int main() {
  76.     ios_base::sync_with_stdio(0);
  77.     cin.tie(0), cout.tie(0);
  78.     if (getenv("INOUT")) {
  79.         freopen("input.in", "r", stdin);
  80.         freopen("input.out", "w", stdout);
  81.     }
  82.     solve();
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement