paysmile 2019. 1. 17. 11:15

#include<iostream>

#include<cstring>

using namespace std;


int n, m;

int arr[301][301];


int calculatesum(int i, int j, int x, int y) {

int sum = 0;

for (int b = j; b <= y; b++){

for (int a = i; a <= x; a++) {

sum += arr[a][b];

}

}

return sum;

}


int main(void) {

cin >> n >> m;


for (int i = 1; i <= n; i++) {

for (int j = 1; j <= m; j++) {

cin >> arr[i][j];

}

}

int test_case;

cin >> test_case;

for (int k = 0; k < test_case; k++) {

int i, j, x, y;

cin >> i >> j >> x >> y;

cout << calculatesum(i, j, x, y) << endl;

}

}