AcWing 798. 差分矩阵
原题链接
简单
作者:
__43
,
2020-09-23 16:33:05
,
所有人可见
,
阅读 302
#include <iostream>
using namespace std;
int d[1010][1010];
void add(int x1,int y1,int x2,int y2,int x)
{
d[x1][y1] += x;
d[x1][y2 + 1] -= x;
d[x2 + 1][y1] -= x;
d[x2 + 1][y2 + 1] += x;
}
int main(void)
{
int n,m,r,x;
cin>>n>>m>>r;
for (int i = 1;i <= n;++i)
for (int j = 1;j <= m;++j)
cin>>x,add(i,j,i,j,x);
while (r--)
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2>>x;
add(x1,y1,x2,y2,x);
}
for (int i = 1;i <= n;++i)
for (int j = 1;j <= m;++j)
d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1],cout<<d[i][j]<<(j == m ? "\n" : " ");
return 0;
}