Approach hintTry it first, then revealHide
Precompute pre[i], the sum of the first i elements, in the constructor; each query is then pre[right + 1] - pre[left] in O(1).
Precompute pre[i], the sum of the first i elements, in the constructor; each query is then pre[right + 1] - pre[left] in O(1).