fork download
  1. /*
  2. Problem D: Quan Chien
  3. Author: WinterWind
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. int sum[1005][1005];
  9.  
  10. int main(){
  11. ios::sync_with_stdio(false);
  12. int n,m, q; cin>>n>>m>>q;
  13. int a[n+1][m+1];
  14. for(int i=1; i<=n; i++){
  15. for(int j=1; j<=m; j++){
  16. cin >> a[i][j];
  17. sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + a[i][j];
  18. }
  19. }
  20. while(q--){
  21. int a1, b1, a2, b2;
  22. cin >> a1 >> b1 >> a2 >> b2;
  23. cout << sum[a2][b2] - sum[a1-1][b2] - sum[a2][b1-1] + sum[a1-1][b1-1] << endl;
  24. }
  25. }
  26.  
Success #stdin #stdout 0s 4380KB
stdin
5 5 2
1 5 4 6 2
7 8 2 0 1
3 5 9 4 2
2 0 4 6 7
3 0 7 7 9
1 1 3 4
2 1 2 5
stdout
54
18