Comments

I don't think this is a correct solution. (or maybe I misinterpreted it)

If I have an array [0,2,4,0] and I want to query (1,4), this solution will yield 10 as answer. (while the answer should be 4)

+28

+7

I like the second meme.

Very helpful. Thanks.

Let Ai (1<=i<=N) equals 10^9, N equals 200000, and K equals N-1. Therefore the grade for each term will be 1000000000^199999. Absolutely overflow.