For interval sum, you can use segment tree.
https://www.cnblogs.com/jason2003/p/9676729.html
This one restores the segment tree as linked lists.
https://www.geeksforgeeks.org/segment-tree-set-1-sum-of-given-range/
This one restores the segment tree as array.
The construction of segment tree from the array is recursion.