A prefix sum array answers range totals in O(1), but one changed value forces you to rebuild O(n) of it. A Fenwick tree, also called a binary indexed tree, trades a little query speed for fast updates: both take O(log n).
The idea fits in two loops. Cell tree[i] stores the total of the last i & -i values ending at position i, where i & -i is the lowest set bit of i. To add to position i, climb with i += i & -i, touching every cell that covers it. To read the prefix up to i, walk down with i -= i & -i, adding disjoint cells. The tree is 1-indexed because 0 has no lowest set bit.
Reach for a Fenwick tree when values change between prefix or range-sum questions, or when you count things "so far" by value: earlier scores below this one, or earlier timestamps above it. Combined with a difference array it also handles range updates with point lookups. For minimums, maximums or more complex merges, use a segment tree instead.
Updates climb by the lowest set bit; prefix reads walk down by it.