比较经典的二维前缀和
2025-11-28 16:49:31
发布于:浙江
0阅读
0回复
0点赞
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,q,c[1078][1091],s[1078][1091];
int main(){
cin>>n>>m>>q;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>c[i][j];
s[i][j]=s[i][j-1]+s[i-1][j]+c[i][j]-s[i-1][j-1];
}
}
int a,b,x,y;
while(q--){
cin>>a>>b>>x>>y;
cout<<s[x][y]-s[x][b-1]-s[a-1][y]<<endl;
}
return 0;
}
这里空空如也






有帮助,赞一个