#FT0000017. Cộng đoạn và tổng đoạn (Range Add Range Sum)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cộng đoạn và tổng đoạn (Range Add Range Sum)
Range Add Range Sum
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of positive integers, indexed from . Support two operations: increase every element in an interval, and obtain the current sum of an interval.
Command 1 l r k increases each element from position through by . As both endpoints are included, exactly elements change and the entire array sum increases by .
Command 2 l r prints the current sum . Previous additions remain in effect; queries do not modify the array. Results may exceed the signed 32-bit integer range.
Input
- Line 1:
n mgives array length and operation count. - Line 2:
a_1 a_2 ... a_ngives the initial values in index order. - Next lines: each line contains one of the following commands, in execution order:
1 l r k: add to all elements in .2 l r: query sum over inclusive interval .
Output
For each 2 l r command, print the requested integer computed from the current state on its own line, in query order. Update commands produce no output.
Subtasks
Subtask 1 (15 points):
- .
- .
- and are positive integers.
- in every command.
- at all times.
Subtask 2 (20 points):
- .
- .
- and are positive integers.
- in every command.
- at all times.
Subtask 3 (65 points):
- .
- .
- and are positive integers.
- in every command.
- at all times.
Examples
Input
4 5
1 2 3 4
2 1 4
1 2 4 3
2 2 3
1 1 1 5
2 1 2
Output
10
11
11
Explanation
There are elements. The initial values are [1, 2, 3, 4].
-
Command 1 —
2 1 4: The sum on is , so print10. -
Command 2 —
1 2 4 3: Add to each element of ; the current array is[1, 5, 6, 7]. -
Command 3 —
2 2 3: The sum on is , so print11. -
Command 4 —
1 1 1 5: Add to each element of ; the current array is[6, 5, 6, 7]. -
Command 5 —
2 1 2: The sum on is , so print11.
Collect the answers to output-producing commands in their input order, printing one answer per line.