Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- ifstream in("zoo.in");
- ofstream out("zoo.out");
- #define cin in
- #define cout out
- long long pre[105][105];
- int n, m;
- long long getSum(int x1, int y1, int x2, int y2) {
- return pre[x2][y2] - pre[x2][y1 - 1] - pre[x1 - 1][y2] + pre[x1 - 1][y1 - 1];
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cin >> n >> m;
- for(int i = 1; i <= n; ++i) {
- for(int j = 1; j <= m; ++j) {
- long long x;
- cin >> x;
- pre[i][j] = x + pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
- }
- }
- int q;
- cin >> q;
- while(q--) {
- int x1, y1, x2, y2;
- cin >> x1 >> y1 >> x2 >> y2;
- cout << getSum(x1, y1, x2, y2) << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment