Need some help in coming up with a data structure for answering this question. The objective is to perform Q queries of the following type on an array:
- Type 1: Given L and R, return
- Type 2: Update position idx with a value val
How to answer these queries efficiently? The naive way is n^2. I was thinking along the lines of maintaining cumulative sum, since A_j factors out of the summation in the above equation.