Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
18545 | 通过 | 【前缀与差分】差分矩阵 | C++ | 通过 | 114 MS | 6300 KB | 695 | 2023-02-26 11:22:04 |
#include <bits/stdc++.h> using namespace std; const int N=1010; int a[N][N],b[N][N]; void chafen(int d,int e,int f,int g,int h){ b[d][e]+=h; b[f+1][g+1]+=h; b[d][g+1]-=h; b[f+1][e]-=h; } int main(){ int n,m,q,x1,y1,x2,y2,c; cin>>n>>m>>q; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; b[i][j]=a[i][j]-a[i-1][j]-a[i][j-1]+a[i-1][j-1]; } } for(int i=0;i<q;i++){ cin>>x1>>y1>>x2>>y2>>c; chafen(x1,y1,x2,y2,c); } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ b[i][j]=b[i][j]+b[i-1][j]+b[i][j-1]-b[i-1][j-1]; } } for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cout<<b[i][j]<<' '; } cout<<endl; } return 0; }