Loading...
Loading...
Loading...
A warehouse has n shelves numbered from 0, all empty. Each of q deliveries adds v units to every shelf from l to r, both included. Print the number of units on each shelf at the end.
Example
Input
8 2 1 4 5 3 6 2
Output
0 5 5 7 7 2 2 0
Shelves 3 and 4 get both deliveries.
Try the problem first. Open one hint at a time.
Looping over every range is too slow when n and q are large.
Record +v at l and -v at r + 1, then take a running total.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor