
代码实现
cpp
typedef long long LL;
const int N = 1e3 + 10;
LL x, st[N][N], n, m, q;
int main()
{
cin >> n >> m >> q;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> x;
st[i][j] = st[i-1][j] + st[i][j-1] - st[i-1][j-1] + x;
}
}
while (q--)
{
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << st[x2][y2] + st[x1-1][y1-1] - st[x1-1][y2] - st[x2][y1-1]<< endl;
}
return 0;
}