题目:P1060 - 【模板】二维前缀和 - ETOJ (eriktse.com)
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
const int N=1e3+23;
using ll=long long;
ll a[N][N],fix[N][N],diff[N][N];
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll n,m,q;cin>>n>>m>>q;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];}}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
fix[i][j]=a[i][j]+fix[i-1][j]+fix[i][j-1]-fix[i-1][j-1];}}
while(q--) {
ll x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
cout<<fix[x2][y2]+fix[x1-1][y1-1]-fix[x2][y1-1]-fix[x1-1][y2]<<'\n';
}
}