← 返回 google 的题目列表Maximum Overlap of Axis-Aligned Rectangles on a Grid
类型:online_judge
Maximum Overlap of Axis-Aligned Rectangles on a Grid
You are given an n x n integer grid indexed from 0 to n - 1 in both dimensions. Initially, every cell is 0.
You are given q inclusive rectangle queries. Each query is represented by four integers [r1, c1, r2, c2], where:
0 <= r1 <= r2 < n
0 <= c1 <= c2 < n
For each query, increment every cell (r, c) satisfying r1 <= r <= r2 and c1 <= c <= c2 by 1.
Return the maximum number of rectangles covering any cell after all queries are applied.
Input Format
n q
r1 c1 r2 c2
r1 c1 r2 c2
...
Output Format
One integer: the maximum value in the grid.
Constraints
1 <= n <= 2000
1 <= q <= 200000
Every rectangle lies within the grid.
Example
Input:
4 3
0 0 1 2
1 1 3 3
2 0 2 2
Output:
3
Explanation: some cells, including cells in the intersection of the three rectangles, are covered multiple times; the maximum coverage is 3.
Example
Input
1 1
0 0 0 0
Output
1