Cummulative sum query

Revision en1, by inception_95, 2017-09-09 13:56:27

There is an array of n numbers and after m number of steps, one needs to answer the query. In every step from 1 to m, we calculate the cumulative sum. Then queries are asked, which index contains which number in the array.

For example, if n = 5, m = 3, the array = 2,4,3,9,1

we conduct the m steps.




If the query is 2, the answer will be 25.

Constraints: 1<=n,m<=10^5

How can I solve this problem?

N.B: It just came to my mind. I didn't find any such problem in any OJ. If you can, please provide the link. And sorry for bad english.

Tags cumulative sum


  Rev. Lang. By When Δ Comment
en1 English inception_95 2017-09-09 13:56:27 643 Initial revision (published)