forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
34 lines (34 loc) · 1.04 KB
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution {
public int[] countRectangles(int[][] rectangles, int[][] points) {
int n = 101;
List<Integer>[] d = new List[n];
Arrays.setAll(d, k -> new ArrayList<>());
for (int[] r : rectangles) {
d[r[1]].add(r[0]);
}
for (List<Integer> v : d) {
Collections.sort(v);
}
int m = points.length;
int[] ans = new int[m];
for (int i = 0; i < m; ++i) {
int x = points[i][0], y = points[i][1];
int cnt = 0;
for (int h = y; h < n; ++h) {
List<Integer> xs = d[h];
int left = 0, right = xs.size();
while (left < right) {
int mid = (left + right) >> 1;
if (xs.get(mid) >= x) {
right = mid;
} else {
left = mid + 1;
}
}
cnt += xs.size() - left;
}
ans[i] = cnt;
}
return ans;
}
}