一维差分
区间 [l,r] 整体加 x,只需要 d[l]+=x、d[r+1]-=x。全部修改结束后对 d 做一次前缀和即可得到最终数组。
时间复杂度 O(n+m)O(n+m)O(n+m),空间复杂度 O(n)O(n)O(n)。
使用您的 星源智一OJ 通用账户