蓝桥OJ3694肖恩的投球游戏plus

二维差分

蓝桥OJ3694肖恩的投球游戏plus_第1张图片

#include
using namespace std;

const int N = 1e3 + 5;
int a[N][N],d[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 >> a[i][j];
			d[i][j] = a[i][j] + a[i-1][j-1] - a[i-1][j] - a[i][j-1];
		}
	}
	while(q--)
	{
		int x1,y1,x2,y2,c;
		cin >> x1 >> y1 >> x2 >> y2 >> c;
		d[x1][y1] += c;
		d[x2 + 1][y2 + 1] += c;
		d[x1][y2 + 1] -= c;
		d[x2 + 1][y1] -= c;
	}
	for (int i = 1 ; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			a[i][j] = d[i][j] - a[i-1][j-1] + a[i-1][j] + a[i][j-1];
			cout << a[i][j] << ' ';
		}
		cout << '\n';
	}
	return 0;
}

 

你可能感兴趣的:(蓝桥杯备赛练习,算法,c++)