Advertisement
gt22

Untitled

Dec 7th, 2019
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <vector>
  2. #include "optimization.h"
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n = readInt(), m = readInt();
  7.     vector<int> l(n), r(n);
  8.     vector<pair<int, int>> points(m);
  9.     for (int i = 0; i < n; ++i) {
  10.         l[i] = readInt();
  11.         r[i] = readInt();
  12.         if(l[i] > r[i]) {
  13.             swap(l[i], r[i]);
  14.         }
  15.     }
  16.     for (int i = 0; i < m; ++i) {
  17.         points[i] = {readInt(), i};
  18.     }
  19.     sort(l.begin(), l.end());
  20.     sort(r.begin(), r.end());
  21.     sort(points.begin(), points.end());
  22.     int curL = -1, curR = -1;
  23.     vector<int> ans(m);
  24.     for (auto po : points) {
  25.         int p = po.first;
  26.         while(curL < n - 1 && l[curL + 1] <= p) {
  27.             curL++;
  28.         }
  29.         while(curR < n - 1 && r[curR + 1] < p) {
  30.             curR++;
  31.         }
  32.         ans[po.second] = curL - curR;
  33.     }
  34.     for(auto a : ans) {
  35.         writeInt(a, ' ');
  36.     }
  37.     writeChar('\n');
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement