From 39cfc3b8c0a51350a222444e9bd37f12d5822897 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Tue, 30 Nov 2021 20:59:10 +0800 Subject: [PATCH] =?UTF-8?q?796.=20=E5=AD=90=E7=9F=A9=E9=98=B5=E7=9A=84?= =?UTF-8?q?=E5=92=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/9139040/ --- AcWing/796/796.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 AcWing/796/796.cpp 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; +}