2024蓝桥杯每日一题(差分)-Python程序代码

时间:2024-03-18 07:33:04
n,m,q = map(int,input().split())
a = [[0]*(m+5)]
for i in range(n):
    a.append([0]+list(map(int,input().split())))
s = [[0]*(m+5) for _ in range(n+5)]
for i in range(q):
    x1,y1,x2,y2,c = map(int,input().split())
    s[x1][y1]+=c
    s[x2+1][y2+1]+=c
    s[x1][y2+1]-=c
    s[x2+1][y1]-=c
for i in range(1,n+1):
    for j in range(1,m+1):
        s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1]
        a[i][j]+=s[i][j]
        print(a[i][j],end=' ')
    print()

四、第四题: 棋盘

解题思路:差分
        差分+取模