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. int sum[n+1][m+1];
  15.  
  16. for(int i=1; i<=n; i++){
  17. sum[i][0] = 0;
  18. for(int j=1; j<=m; j++){
  19. cin >> a[i][j];
  20. sum[i][j] = sum[i][j-1] + a[i][j];
  21. }
  22. }
  23. while(q--){
  24. int a1, b1, a2, b2;
  25. cin >> a1 >> b1 >> a2 >> b2;
  26. int tong = 0;
  27. for(int i=a1; i<=a2; i++){
  28. tong += sum[i][b2] - sum[i][b1-1];
  29. }
  30. cout << tong << endl;
  31. }
  32. }
  33.  
Success #stdin #stdout 0s 4456KB
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