sbl

鑫鑫  •  9个月前


include <stdio.h>

long long sum [1010][1010]; int a[1010][1010];

int main() {

int  n, m, i, j, d = 0, x1, x2, y1, y2, q;
scanf("%d%d%d", &n, &m, &q);
for (i = 1; i <= n; i++) {
	for (j = 1; j <= m; j++) {
		scanf("%d", &a[i][j]);
	}
}
for (i = 1; i <= n; i++) {
	for (j = 1; j <= m; j++) {
		sum[i][j] = sum[i - 1][j] + sum[i][j - 1] + sum[i - 1][j - 1] + a[i][j];
	}
}
for (i = 0; i < q; i++) {
	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	d = sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
	printf("%d\n", d);
	d = 0;
}
return 0;

}


评论:

请先登录,才能进行评论