#include <iostream>
int N, M, K;
int i, j, x, y;
int arr[301][301];
int main(int argc, char** argv){
scanf("%d %d", &N, &M);
for(int i=0; i<N; i++){
for(int j=0; j<M; j++){
scanf("%d", &arr[i+1][j+1]);
}
}
scanf("%d", &K);
for(int r=0; r<K; r++){
int sum = 0;
scanf("%d %d %d %d", &i, &j, &x, &y);
for(int n=i; n<=x; n++){
for(int m=j; m<=y;m++){
sum += arr[n][m];
}
}
printf("%d\n", sum);
}
return 0;
}
2 3
1 2 4
8 16 32
3
1 1 2 3
1 2 1 2
1 3 2 3
헷갈리면 안된다.
1 3 2 3 -> (1,3)에서 (2,3)까지 다 더하는게 아니라 (1,3)이랑 (2,3)만 더하면 된다. x범위, y범위에서만 이렇게 더하면 된다. 굳이 더 심하게 복잡하게 고려하지 않아도 되는 듯.