-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11658.cpp
40 lines (33 loc) · 923 Bytes
/
11658.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<iostream>
#include<cstdio>
using namespace std;
int A[1025][1025] = {0};
int prefix[1025][1025] = {0};
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio();
int N, M, w, x1, y1, x2, y2, c;
cin >> N >> M;
for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++){
cin >> c;
A[i][j] = c;
prefix[i][j] = prefix[i-1][j] + prefix[i][j-1] - prefix[i-1][j-1] + c;
}
}
for(int m=0; m<M; m++){
cin >> w;
if(w==0){
cin >> x1 >> y1 >> c;
for(int i=x1; i<=N; i++){
for(int j=y1; j<=N; j++){
prefix[i][j] = prefix[i][j] + c - A[i][j];
}
}
A[x1][y1] = c;
}else{
cin >> x1 >> y1 >> x2 >> y2;
cout << prefix[x2][y2] - prefix[x2][y1-1] - prefix[x1-1][y2] + prefix[x1-1][y1-1] << '\n';
}
}
}