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 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];//公式
18
19 int x1,y1, x2,y2;//左上角和右下角下标
20 for(int i = 0;i < q;++i){
21 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 }