diff --git a/AcWing/796/796.cpp b/AcWing/796/796.cpp new file mode 100644 index 00000000..e2442bb5 --- /dev/null +++ b/AcWing/796/796.cpp @@ -0,0 +1,27 @@ +#include + +using std::cin; +using std::cout; +using std::endl; + +int n, m, q, g[1005][1005], sum[1005][1005]; + +int main() { + cin >> n >> m >> q; + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + cin >> g[i][j]; + } + } + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= m; j++) { + sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + g[i][j]; + } + } + while (q--) { + int x1, y1, x2, y2; + cin >> x1 >> y1 >> x2 >> y2; + cout << sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1] << endl; + } + return 0; +}