并且这里要注意:此题必须要用scanf,printf,long long!
#include <bits/stdc++.h>
using namespace std;
int n,m,q,x,y,l;
long long a[2050][2050],ss[2050][2050],t;
int main()
{
scanf("%d%d",&n, &m);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
scanf("%lld", &a[i][j]);
for(int i = 1; i <= n; i++)
for(int j = m; j >= 1; j--)
a[i][j] += a[i - 1][j];
for(int i = 1; i <= n; i++)
for(int j = m; j >= 1; j--)
a[i][j] += a[i][j + 1];
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
ss[i - j + 1000][j] = ss[i - j + 1000][j - 1] + a[i][j];
scanf("%d",&q);
while(q--)
{
scanf("%d%d%d",&x,&y,&l);
t = a[x + l - 1][y];
int ri,le;
ri = min(m,y + l);
if (x > 1) le = y - 1;
else le = y;
t -= (ss[x - y + 999][ri] - ss[x - y + 999][le]);
if(x > 1) le = y;
else le = min(m,y + 1);
t += (ss[x - y + 998][ri] - ss[x - y + 998][le]);
printf("%lld\n", t);
}
return 0;
}