二维差分
b[x1][y1] += c;
b[x2 + 1][y1] -= c;
b[x1][y2 + 1] -= c;
b[x2 + 1][y2 + 1] += c;
import java.util.*;
public class Main {
static int N = 1010;
static int[][] b = new int[N][N];
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
int q = input.nextInt();
// 构造差分数组
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int a = input.nextInt();
insert(i, j, i, j, a);
}
}
// q次操作
while (q-- > 0) {
int x1 = input.nextInt();
int y1 = input.nextInt();
int x2 = input.nextInt();
int y2 = input.nextInt();
int c = input.nextInt();
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][j - 1] + b[i - 1][j] - b[i - 1][j - 1];
}
}
// 输出
for (int i = 1; i <= n; i++ ) {
for (int j = 1; j <= m; j++) {
System.out.print(b[i][j] + " ");
}
System.out.println();
}
}
public static void insert(int x1, int y1, int x2, int y2, int c) {
b[x1][y1] += c;
b[x2 + 1][y1] -= c;
b[x1][y2 + 1] -= c;
b[x2 + 1][y2 + 1] += c;
}
}