Greg and array
Time: 1 s · Memory: 256 MB
- Prefix sums
Statement
Greg has an array of numbers and operations. Operation is : is added to each of the elements .
Then queries come: all operations with numbers from to must be applied. Queries are applied one after another, and an operation may be applied several times. Print the array after all queries.
Input format
The first line contains , , (). The second line contains integers (). The next lines contain , , (, ). The next lines contain and ().
Output format
A single line with numbers — the final array.
Examples
Input
3 3 3 1 2 3 1 2 1 1 3 2 2 3 4 1 2 1 3 2 3
Output
9 18 17
Input
1 1 1 1 1 1 1 1 1
Output
2
Note
A two-level difference array. First find from the queries how many times every operation is applied: , and prefix sums. Then operation adds to the array — write that with a difference array too and take prefix sums at the end. Everything is .
Values reach — a 64-bit type is needed. In the first example the answer is 9 18 17.
Source: Codeforces, problem 295A.
