Count Number of Rectangles Containing Each Point LeetCode solution in C++
1class Solution {2public:3vector<int> countRectangles(vector<vector<int>> &rectangles, vector<vector<int>> &points) {4int i, count, ind, x, y, n = rectangles.size();56vector<int> ans;7vector<vector<int>> heights(101);89for (auto rect : rectangles) heights[rect[1]].push_back(rect[0]);1011for (i = 0; i < 101; i++) sort(heights[i].begin(), heights[i].end());1213for (auto point : points) {14count = 0;15x = point[0];16y = point[1];17for (i = y; i < 101; i++) {18ind = lower_bound(heights[i].begin(), heights[i].end(), x) - heights[i].begin();19count += (heights[i].size() - ind);20}21ans.push_back(count);22}23return ans;24}25};