-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgold-mines-10.cpp
52 lines (48 loc) · 1.02 KB
/
gold-mines-10.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
#include<bits/stdc++.h>
using namespace std;
int main(){
int i,j,t,n,r,c,q;
int x1,y1,x2,y2;
long long gold,temp;
int g[1001][1001]={0};
long long dp[1001][1001]={0};
cin>>r>>c;
for(i=1;i<=r;++i){
temp=0;
for(j=1;j<=c;++j){
cin>>g[i][j];
temp+=g[i][j];
dp[i][j]=temp;
}
}
/*for(i=1;i<=r;++i){
for(j=1;j<=c;++j){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
for(i=1;i<=r;++i){
for(j=1;j<=c;++j){
dp[i][j]+= dp[i-1][j];
}
cout<<endl;
}
/*for(i=1;i<=r;++i){
for(j=1;j<=c;++j){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
cin>>q;
while(q--){
cin>>x1>>y1>>x2>>y2;
gold=0;
gold+= dp[x2][y2]-dp[x1-1][y2]-dp[x2][y1-1]+dp[x1-1][y1-1];
/*for(i=x1;i<=x2;++i){
for(j=y1;j<=y2;++j){
gold+= g[i][j];
}
}*/
cout<<gold<<endl;
}
}