二阶差分

例:给区间[L,R]加首项为s,公差为d的等差数列

a[ ]表示原数组,b[ ]表示a的差分数组,c[ ]表示b的差分数组

a[i] = a[i]+s+(i-L)*d , L<=i<=R

b[L] = a[L]+s-a[L-1] = b[L]+s

b[i] = a[i]+d-a[i-1] = b[i]+d , L<i<=R

b[R+1] = a[R+1]-[a[R]+s+(R-L)*d] = b[R+1]-s-(R-L)*d

c[L] = b[L]+s-b[L-1] = c[L]+s

c[L+1] = b[L+1]+d-(b[L]+s) = c[L+1]+d-s

c[i] = b[i]-b[i-1] = c[i] , L<i<=R

c[R+1] = b[R+1]-s-(R-L)*d-b[R] = c[R+1]-s-(R-L)*d

c[R+2] = b[R+2]-[b[R+1]-s-(R-L)*d] = c[R+2]+s+(R-L)*d

对c数组求一次前缀和得b数组,再求一次得a数组

 

posted @ 2020-03-03 18:52  TRTTG  阅读(1218)  评论(4编辑  收藏  举报