1 #include <iostream>
2
3 using namespace std;
4
5 const int N = 1000+10;
6 int arr[N][N] = {0}, s[N][N] = {0};
7 int n, m, q;
8
9 int main(){
10 cin >> n >> m >> q;
11 for(int i = 1;i <= n;++i)
12 for(int j = 1;j <= m;++J)
13 is CIN >> ARR [I] [J];
14
15 for ( int I = . 1 ; I <= n-; ++ I)
16 for ( int J = . 1 ; J <= m; ++ J)
. 17 S [I] [J] = S [I- . 1 ] [J] + S [I] [J- . 1 ] - S [I- . 1 ] [J- . 1 ] + ARR [I] [J]; // equation
18 is
. 19 int X1, Y1, X2, Y2; // left and right corners index
20 is for ( int I = 0 ; I <Q; ++ I) {
21 is cin >> x1 >> y1 >> x2 >> y2;
22 cout << s[x2][y2] - s[x1-1][y2] - s[x2][y1-1] + s[x1-1][y1-1] << endl;
23 }
24
25 return 0;
26 }