AcWing 798. 差分矩阵-python3
原题链接
简单
作者:
机械佬也想学编程
,
2020-07-02 20:34:58
,
所有人可见
,
阅读 624
def insert(x1, y1, x2, y2, c): # 构造差分矩阵
b[x1][y1] += c
b[x1][y2+1] -= c
b[x2+1][y1] -= c
b[x2+1][y2+1] += c
n, m, q = map(int, input().split())
a = [] # 原矩阵
b= [[0] * (m+10) for _ in range(n+10)] # 差分矩阵
for _ in range(n):
row = list(map(int, input().split()))
a. append(row)
for _ in range(q):
x1, y1, x2, y2, c = map(int, input().split())
insert(x1, y1, x2, y2, c)
for i in range(1, n+1):
for j in range(1, m+1):
b[i][j] = b[i][j-1] + b[i-1][j] - b[i-1][j-1] + b[i][j] # 求和
print(b[i][j]+ a[i-1][j-1], end=" ")
print()
好