璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:luogup3397
problems
名称地毯
题目编号P3397
题目链接luogu.com.cn/…
来源Luogu
算法分类差分
难易程度容易

地毯

想法

先处理竖向的差分,后处理横向的差分。

代码实现

#include<cstdio>
 
int h[1010][1010];
int main() {
	int n, m, x1, y1, x2, y2;
	scanf("%d %d", &n, &m);
	for(int i=1; i<=m; i++) {
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		h[x1][y1]++;
		h[x2+1][y1]--;
		h[x1][y2+1]--;
		h[x2+1][y2+1]++;
	}
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++) 
			h[i][j] = h[i][j] + h[i-1][j];
 
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			h[i][j] = h[i][j] + h[i][j-1];
 
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++)
			printf("%d ", h[i][j]);
		printf("\n");
	}
	return 0;
}
/app/www/public/data/pages/icpc/problems/luogup3397.txt · 最后更改: 2024/02/18 15:26 由 温婕莺