#FT0000016. Những truy vấn kinh khủng (Horrible Queries)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những truy vấn kinh khủng (Horrible Queries)
Horrible Queries
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Initially you have an array of zeros, indexed from through . Process operations of two types: add to an entire range, or ask for a range sum.
Command 0 l r v adds to each element of the inclusive interval . Overlapping updates accumulate. Command 1 l r asks for the current sum .
Operations are processed in order. There is no input line containing initial array values, since all initial values are prescribed to be zero. The exact query result may require a wide integer type.
Input
- Line 1:
n cgives array length and number of operations. - Next lines: each line contains one of the following commands, in execution order:
0 l r v: add to every element in .1 l r: query sum over inclusive interval .
Output
For each 1 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 (20 points):
- .
- .
- .
- .
- all elements are initially .
Subtask 2 (30 points):
- .
- .
- .
- .
- all elements are initially .
Subtask 3 (50 points):
- .
- .
- .
- .
- all elements are initially .
Examples
Input
8 6
0 2 4 26
0 4 8 80
0 4 5 20
1 8 8
0 5 7 14
1 4 8
Output
80
508
Explanation
There are elements. The initial values are [0, 0, 0, 0, 0, 0, 0, 0].
-
Command 1 —
0 2 4 26: Add to each element of ; the current array is[0, 26, 26, 26, 0, 0, 0, 0]. -
Command 2 —
0 4 8 80: Add to each element of ; the current array is[0, 26, 26, 106, 80, 80, 80, 80]. -
Command 3 —
0 4 5 20: Add to each element of ; the current array is[0, 26, 26, 126, 100, 80, 80, 80]. -
Command 4 —
1 8 8: The sum on is , so print80. -
Command 5 —
0 5 7 14: Add to each element of ; the current array is[0, 26, 26, 126, 114, 94, 94, 80]. -
Command 6 —
1 4 8: The sum on is , so print508.
Collect the answers to output-producing commands in their input order, printing one answer per line.