You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
885 B
28 lines
885 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
const int N = 1010;
|
|
int b[N][N], s[N][N];
|
|
int n, m;
|
|
|
|
int main() {
|
|
cin >> n >> m;
|
|
while (m--) {
|
|
// 从0开始构建差分数组
|
|
int x1, y1, x2, y2;
|
|
cin >> x1 >> y1 >> x2 >> y2;
|
|
b[x1][y1] += 1; // 进行子矩阵的加减,差分
|
|
b[x2 + 1][y1] -= 1;
|
|
b[x1][y2 + 1] -= 1;
|
|
b[x2 + 1][y2 + 1] += 1;
|
|
}
|
|
// 还原为原始数组
|
|
for (int i = 1; i <= n; i++) {
|
|
for (int j = 1; j <= n; j++) {
|
|
s[i][j] = b[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1]; // 把之前的加减结果进行求和
|
|
printf("%d ", s[i][j]); // 注意输出格式,每个数带一个空格
|
|
}
|
|
printf("\n"); // 结束一行的输出输出一个换行符号
|
|
}
|
|
return 0;
|
|
} |