-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathback_11660.cpp
More file actions
45 lines (40 loc) · 899 Bytes
/
back_11660.cpp
File metadata and controls
45 lines (40 loc) · 899 Bytes
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
#include <iostream>
using namespace std;
int map[1025][1025];
long long dp[1025][1025];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int a, b, piror = 0;
cin >> a >> b;
for (int i = 1; i <=a; i++)
{
for (int j = 1; j <= a; j++)
{
cin >> map[i][j];
}
}
for (int i = 1; i <= a; i++)
{
for (int j =1; j<= a; j++)
{
dp[i][j] = map[i][j] + dp[i][j-1] + dp[i-1][j]- dp[i-1][j-1];
}
}
for (int i = 0; i<b; i++)
{
int a1, a2, b1, b2;
cin >> a1 >> a2 >> b1 >> b2;
cout << dp[b1][b2] +dp[a1-1][a2-1] - dp[a1-1][b2] - dp[b1][a2-1] << "\n";
}
// for (int i = 1; i <=a; i++)
// {
// for (int j = 1; j <= a; j++)
// {
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
return 0;
}