-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaekjoon11660.cpp
59 lines (49 loc) · 1.12 KB
/
baekjoon11660.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
using namespace std;
int N, M,a, b, c, d;
int arr[1025][1025];
int dp[1025][1025];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
cin>>arr[i][j];
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
dp[i][j] = dp[i][j-1] + arr[i][j];
}
}
for (int i = 0; i < M; i++) {
int result = 0;
cin >> a>> b>>c>> d;
for (int i = a; i <= c; i++) {
result += (dp[i][d] - dp[i][b - 1]);
}
cout << result << "\n";
}
}
/////////////////////////////////////////////////////////////////
#include <iostream>
using namespace std;
int N,M, x, y, x2, y2;
int arr[1025][1025], dp[1025][1025];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N>>M;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
cin >> arr[i][j];
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + arr[i][j];
}
}
for (int i = 0; i < M; i++) {
cin >> x >> y >> x2 >> y2;
int result = dp[x2][y2] - dp[x - 1][y2] - dp[x2][y - 1] + dp[x - 1][y - 1];
cout << result << "\n";
}
}