E2E 金线学习页

前缀和

前缀和数组 Si=∑k=1iakS_i = \sum_{k=1}^{i} a_k,任意区间和 [l,r][l, r] 等于 Sr−Sl−1S_r - S_{l-1}。

差分

差分是前缀和的逆运算:对区间 [l,r][l, r] 加 vv,只需 dl+=vd_l \mathrel{+}= v,dr+1−=vd_{r+1} \mathrel{-}= v。

This content comes from OI Wiki: E2E 金线学习页. See the original for authors and revision history. AIOJ has adapted the formatting, in-site links, and resource paths.

Content is shared under CC BY-SA 4.0 and SATA license; additional terms are governed by the original notice. Thanks to the OI Wiki authors and contributors; per the SATA terms, please visit the OI Wiki repository and star it to show your support.