终于一遍过了

#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1010;

int n, m, q;
LL d[N][N];

void insert(int x1, int y1, int x2, int y2, int k) {
    d[x1][y1] += k;
    d[x1][y2 + 1] -= k;
    d[x2 + 1][y1] -= k;
    d[x2 + 1][y2 + 1] += k;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> m >> q;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            int v;
            cin >> v;
            insert(i, j, i, j, v);
        }
    }

    while (q--) {
        int x1, y1, x2, y2, k;
        cin >> x1 >> y1 >> x2 >> y2 >> k;
        insert(x1, y1, x2, y2, k);
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1];
        }
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cout << d[i][j] << ' ';
        }
        cout << '\n';
    }

    return 0;
}