fork download
  1. #include <iostream>
  2. using namespace std;
  3. typedef long long int ll;
  4. int main()
  5. {
  6. ll m, n, c, area[1001][1001], temp, x1, y1, x2, y2, ar;
  7. cin>>m>>n;
  8. for (int i = 1; i <= m; i++)
  9. {
  10. for (int j = 1; j <= n; j++)
  11. {
  12. cin>>temp;
  13. area[i][j] = temp;
  14. area[i][j] = temp + area[i][j-1] + area[i-1][j] - area[i-1][j-1];
  15. }
  16. }
  17. cin>>c;
  18. for (int i = 0; i < c; i++)
  19. {
  20. cin>>x1>>y1>>x2>>y2;
  21. ar = area[x2][y2] + area[x1-1][y1-1] - area[x1-1][y2] - area[x2][y1-1];
  22. cout<<ar<<"\n";
  23. }
  24. }
  25.  
Success #stdin #stdout 0s 11168KB
stdin
Standard input is empty
stdout
Standard output is empty