AcWing 798. 差分矩阵
原题链接
简单
作者:
wjie
,
2020-07-01 17:28:23
,
所有人可见
,
阅读 478
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1e3 + 5;
int arr[N][N];
int main()
{
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
int tmp;
scanf("%d", &tmp);
arr[i][j] += tmp;
arr[i+1][j] -= tmp;
arr[i][j+1] -= tmp;
arr[i+1][j+1] += tmp;
}
}
while (k--)
{
int x1, y1, x2, y2, c;
scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &c);
arr[x1][y1] += c;
arr[x1][y2+1] -= c;
arr[x2+1][y1] -= c;
arr[x2+1][y2+1] += c;
}
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
arr[i][j] += arr[i-1][j] + arr[i][j-1] - arr[i-1][j-1];
printf("%d ", arr[i][j]);
}
printf("\n");
}
return 0;
}