別再一堆for或是while了
#include
using namespace std;
int main(){
int n, m, x1, y1, x2, y2, total[505][505];
while (cin >> n >> m){
for (int a = 1; a <= n; a++)
for (int b = 1; b <= n; b++){
cin >> total[a][b];
total[a][b] += total[a - 1][b] + total[a][b - 1] - total[a - 1][b - 1];
}
while (m--){
cin >> x1 >> y1 >> x2 >> y2;
cout << total[x2][y2] - total[x1 - 1][y2] - total[x2][y1 - 1] + total[x1 - 1][y1 - 1] << endl;
}
}
return 0;
}