#SGM0000030. Truy vấn khủng khiếp (Horrible Queries)
Truy vấn khủng khiếp (Horrible Queries)
Horrible Queries
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Maintain an initially zero array under range addition and range-sum queries.
Input
The first line contains integers . Each of the next lines is an operation.
0 p r v: add to every element between positions and , inclusive. If , use the interval from to .1 p r: print the sum on that inclusive interval.
Output
For every type 1 operation, print the requested sum on its own line.
Subtasks
- 20 points: .
- 30 points: .
- 50 points: ; ; .
Examples
Input
5 5
0 1 3 2
1 1 5
0 2 5 1
1 3 4
1 1 2
Output
6
4
5
Explanation
After the first addition the array is 2 2 2 0 0, so the first answer is . After the second addition it becomes 2 3 3 1 1, giving and for the remaining queries.