You are on page 1of 1

#include <bits/stdc++.

h>

using namespace std;

int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
vector <vector <int>> v(n+1, vector <int> (m+1,0));
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
cin>>v[i][j];
}
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
v[i][j] += v[i-1][j] + v[i][j-1] - v[i-1][j-1];
}
}
int x;
cin>>x;
for(int i=1; i<=x; i++)
{
int lx, ly, rx, ry;
cin>>lx>>ly>>rx>>ry;
int res = v[rx][ry]-v[lx-1][ry]-v[rx][ly-1]+v[lx-1][ly-1];
cout<<res<<"\n";
}
}

You might also like