使用快速读入输出
import java.io.*;
public class Main{
static int N = 1010;
static int [][] b = new int[N][N];
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;
}
public static void main(String args[]) throws Exception{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
String arg[]= bf.readLine().split(" ");
int n = Integer.parseInt(arg[0]), m = Integer.parseInt(arg[1]), q = Integer.parseInt(arg[2]);
int [][] a= new int[N][N];
for(int i = 1; i <= n; i++){
String s[] = bf.readLine().split(" ");
for(int j = 1; j <= m; j++) a[i][j] = Integer.parseInt(s[j - 1]);
}
//构建差分矩阵
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++) insert(i, j, i, j, a[i][j]);
}
while( q > 0){
String s[]= bf.readLine().split(" ");
int x1 = Integer.parseInt(s[0]), y1 = Integer.parseInt(s[1]), x2 = Integer.parseInt(s[2]),
y2 = Integer.parseInt(s[3]), c = Integer.parseInt(s[4]);
insert(x1, y1, x2, y2, c);
q--;
}
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++){
log.write(b[i][j] +" ");
}
log.write("\n");
}
log.flush();
bf.close();
log.close();
}
}