코딩테스트/백준
[실1] 15724 - 주지수
ShovelingLife
2022. 10. 24. 23:22
#include <iostream>
#include <string>
using namespace std;
#define SIZE 1050
int n, m, t, arr[SIZE][SIZE]{ 0 };
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m ; j++)
{
int a; cin >> a;
arr[i][j] = a + arr[i - 1][j] + arr[i][j - 1] - arr[i - 1][j - 1];
}
}
cin >> t;
while (t--)
{
int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2;
cout << arr[x2][y2] - arr[x1 - 1][y2] - arr[x2][y1 - 1] + arr[x1 - 1][y1 - 1] << '\n';
}
}