Add, Assign, Range Sum — Solution & Editorial
A Fenwick tree gives O(log N) point add and prefix sum; assignment is an add of (new − old). Range sum = prefix(r) − prefix(l−1).
Complexity: O((N + Q) log N)
Watch out: Sums reach ~1011 — 64-bit.
A Fenwick tree gives O(log N) point add and prefix sum; assignment is an add of (new − old). Range sum = prefix(r) − prefix(l−1).
Complexity: O((N + Q) log N)
Watch out: Sums reach ~1011 — 64-bit.