← 返回 google 的题目列表Count Rectangle Coverage on a Grid
类型:online_judge
Count Rectangle Coverage on a Grid
You are given an n × n grid initially filled with 0s and a list of rectangular update operations. Each rectangle adds 1 to every cell it covers.
Implement:
range_add_counts(n, rectangles)
Each rectangle is represented as:
[row1, col1, row2, col2]
Coordinates are zero-based and both endpoints are inclusive. In other words, a rectangle covers every cell (row, col) satisfying:
row1 <= row <= row2
col1 <= col <= col2
Return the final n × n coverage-count matrix, where each cell contains the number of rectangles covering that position.
Input Format
Read from standard input:
n m
row1 col1 row2 col2
... (m lines total)
n is the side length of the grid.
m is the number of rectangles.
Each of the next m lines contains four integers describing one rectangle.
Output Format
Print n lines. Each line contains n space-separated integers representing one row of the final matrix.
Example
Input:
3 2
0 0 1 1
1 1 2 2
Output:
1 1 0
1 2 1
0 1 1
Constraints
1 <= n <= 500
0 <= m <= 100000
0 <= row1 <= row2 < n
0 <= col1 <= col2 < n
Example
Input
1 0
Output
0