fork download
  1. /*
  2. * @Author: hungeazy
  3. * @Date: 2026-03-04 23:24:15
  4. * @Last Modified by: hungeazy
  5. * @Last Modified time: 2026-04-02 23:45:45
  6. */
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. #define int long long
  10. const int N = (int)1e3+10;
  11. int n,m,q,a[N][N],pre[N][N];
  12.  
  13. int get(int u, int v, int x, int y) {
  14. return pre[x][y]-pre[u-1][y]-pre[x][v-1]+pre[u-1][v-1];
  15. }
  16.  
  17. signed main()
  18. {
  19. ios_base::sync_with_stdio(false);
  20. cin.tie(NULL); cout.tie(NULL);
  21. cin >> n >> m >> q;
  22. for (int i = 1; i <= n; i++)
  23. for (int j = 1; j <= m; j++) cin >> a[i][j];
  24. for (int i = 1; i <= n; i++)
  25. for (int j = 1; j <= m; j++)
  26. pre[i][j] = pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+a[i][j];
  27. while (q--)
  28. {
  29. int u,v,x,y;
  30. cin >> u >> v >> x >> y;
  31. cout << get(u,v,x,y) << endl;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty