AcWing 798. 差分矩阵
原题链接
简单
作者:
Coinisi.
,
2022-12-12 21:50:12
,
所有人可见
,
阅读 147
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#define IOS std::ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define int long long
const int N = 1003;
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
int n, m, q;
int a[N][N], b[N][N];
void insert(int x1, int y1, int x2, int y2, int c)
{
b[x1][y1] = b[x1][y1] + c;
b[x1][y2 + 1] = b[x1][y2 + 1] - c;
b[x2 + 1][y1] = b[x2 + 1][y1] - c;
b[x2 + 1][y2 + 1] = b[x2 + 1][y2 + 1] + c;
}
void solve()
{
cin >> n >> m >> q;
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
cin >> a[i][j];
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
insert(i, j, i, j, a[i][j]);
while( q -- )
{
int x1, y1, x2, y2, c;
cin >> x1 >> y1 >> x2 >> y2 >> c;
insert(x1, y1, x2, y2, c);
}
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= m; j ++)
b[i][j] = b[i][j] + b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= m; j ++)
cout << b[i][j] << ' ';
cout << endl;
}
}
signed main()
{
IOS; int T = 1;
// cin >> T;
while( T -- ) solve();
return 0;
}