# Acwing 796

·  阅读 531

#### 数据范围

1≤n,m≤1000
1≤q≤100000
1≤x1≤x2≤n
1≤y1≤y2≤m
−1000≤c≤1000
−1000≤矩阵内元素的值≤1000

3 4 3
1 2 2 1
3 2 2 1
1 1 1 1
1 1 2 2 1
1 3 2 3 2
3 1 3 4 1

2 3 4 1
4 3 4 1
2 2 2 2

#### 思路

//foreverking
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;

const int N = 1010;

int n,m,q;
int a[N][N],b[N][N];

void insert(int x1,int y1,int x2,int y2,int c){
b[x1][y1] += c;
b[x1][y2 + 1] -= c;
b[x2 + 1][y1] -= c;
b[x2 + 1][y2 + 1] += c;
}

int main(){
cin >> n >> m >> q;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> a[i][j];//输入原数组

for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
insert(i,j,i,j,a[i][j]);//构建差分数组B
//b[i][j] = a[i][j] - a[i - 1][j] - a[i][j - 1] + a[i -1][j - 1];

while(q--){
int x1,x2,y1,y2,c;
cin >> x1 >> y1 >> x2 >> y2 >> c;
insert(x1,y1,x2,y2,c);
}
// for(int i = 1; i <= n; i++)
//     for(int j = 1; j <= m; 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++){
//b[i][j] += b[i - 1][j] + b[i][j - 1] - b[i - 1][j -1];//求二维前缀和
cout << b[i][j] << " ";
}
cout << endl;
}

return 0;
}