题目描述
blablabla
样例
blablabla
算法1
做这道题的时候注意S[i][j]的左右包含关系。建议先在纸上想明白。
+c | +c | |
+c | +c |
C++ 代码
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string>
#include <algorithm>
using namespace std;
const int N = 1010;
int a[N][N];
int S[N][N];
int main()
{
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> S[i][j];
a[i][j] = S[i][j] - S[i - 1][j] - S[i][j - 1] + S[i - 1][j - 1];
}
}
while (q--)
{
int x1, y1, x2, y2, c;
cin >> x1 >> y1 >> x2 >> y2 >> c;
a[x1][y1] += c, a[x1][y2 + 1] -= c, a[x2 + 1][y1] -= c, a[x2 + 1][y2 + 1] += c;
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + a[i][j];
cout << S[i][j] << " ";
}
cout << endl;
}
}