2251.cpp (819B)
1 class Solution { 2 public: 3 vector<int> fullBloomFlowers(const vector<vector<int>> &flowers, const vector<int> &people) const { 4 vector<int> start, finish, res; 5 6 start.reserve(flowers.size()); 7 finish.reserve(flowers.size()); 8 for (const auto &flower : flowers) { 9 start.push_back(flower[0]); 10 finish.push_back(flower[1] + 1); 11 } 12 13 sort(begin(start), end(start)); 14 sort(begin(finish), end(finish)); 15 16 res.reserve(people.size()); 17 for (const int person : people) { 18 const int left = upper_bound(begin(start), end(start), person) - begin(start); 19 const int right = upper_bound(begin(finish), end(finish), person) - begin(finish); 20 res.push_back(left - right); 21 } 22 return res; 23 } 24 };