Assume we have an limit range array[0,1,…,n-1]. We should
Get the sum range from i to j, which $i,j \in [0,n-1]$ and $i<=j$.
Update the elements.
A brute force way is to solve by preprocessing the array, calculate and store sum range from $0$ to $i$, then we can get the sum range from i to j by calculate array[j] - array[i], in this way, the update time complexity would be O(n) on average, and the cost for getting the sum after update is O(1).
But under certain circumstance, we may update a lot, can we do better than linear time?
The answer is yes(if not, the article would be meaningless.), we can acheive an average time complexity O(logn) by using Segment Tree.
Assume now we have an array [2,4,6,8,10], the tree will be,
How to construct the segment tree? We can start with the root, whose range should be [0,1,…,n-1], then split it into halves until the range size reaches 1. The left child of root will be [0,1,…(n-1)/2], and the right part will be [(n-1)/2+1,…n-1].