AlexNeagu11

Untitled

Feb 23rd, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. ifstream in("zoo.in");
  5. ofstream out("zoo.out");
  6.  
  7. #define cin in
  8. #define cout out
  9.  
  10. long long pre[105][105];
  11. int n, m;
  12.  
  13. long long getSum(int x1, int y1, int x2, int y2) {
  14. return pre[x2][y2] - pre[x2][y1 - 1] - pre[x1 - 1][y2] + pre[x1 - 1][y1 - 1];
  15. }
  16.  
  17. int main() {
  18. ios_base::sync_with_stdio(false);
  19. cin.tie(0);
  20.  
  21. cin >> n >> m;
  22. for(int i = 1; i <= n; ++i) {
  23. for(int j = 1; j <= m; ++j) {
  24. long long x;
  25. cin >> x;
  26. pre[i][j] = x + pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
  27. }
  28. }
  29.  
  30. int q;
  31. cin >> q;
  32. while(q--) {
  33. int x1, y1, x2, y2;
  34. cin >> x1 >> y1 >> x2 >> y2;
  35. cout << getSum(x1, y1, x2, y2) << '\n';
  36. }
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment