题目
思路
本思路来自:AcWing 797. 差分 【c++详细题解】 - AcWing
代码
python
n,m = map(int,input().split())
a=list(map(int,input().split()))
a.insert(0,0) # 使下标从1开始
b=[0 for _ in range(n+5)] # b的列表开得足够大才不会超出index
for i in range(1,n+1):
b[i]=a[i]-a[i-1]
for _ in range(m):
l,r,c=map(int,input().split())
b[l]+=c
b[r+1]-=c
# print(a)
# print(b)
for i in range(1,n+1):
a[i]=b[i]+a[i-1]
print(a[i],end=' ')