Loading...
Loading...
Loading...
You have the daily revenue for n days, numbered 1 to n. Answer q questions. Each question gives two days l and r, and asks for the total revenue from day l to day r, both included.
Example
Input
5 3 4 2 7 1 6 1 3 2 5 4 4
Output
13 16 1
The totals are 13, 16 and 1.
Try the problem first. Open one hint at a time.
Adding up each range separately is O(n) per question, which is too slow when q is large.
Build a list where entry i holds the total of the first i days. Then each question is one subtraction.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor