暴力枚举的兄弟们有福了
2026-04-06 10:34:25
发布于:北京
1阅读
0回复
0点赞
二维前缀和,纯公式!上代码
#include <bits/stdc++.h>
#include <ostream>
using namespace std ;
int a[1010][1010] ;
int b[1010][1010] ;
int main () {
int 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] ;
b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1] + a[i][j] ;
}
}
int a , c , x , y ;
for(int i = 1 ; i <= q ; i++) {
cin >> a >> c >> x >> y ;
cout << b[x][y] - b[x][c - 1] - b[a - 1][y] + b[a - 1][c - 1] << endl;
}
return 0 ;
}
这里空空如也

有帮助,赞一个