#P3372. 【模板】线段树 1
【模板】线段树 1
Description
As stated, given a sequence , you need to perform the following two operations:
- Add to every number in a given interval.
- Find the sum of all numbers in a given interval.
Input Format
The first line contains two integers , representing the number of elements in the sequence and the total number of operations.
The second line contains space-separated integers , where the -th integer is the initial value of the -th element.
Each of the next lines contains or integers representing an operation, as follows:
1 x y k: add to every number in the interval .2 x y: output the sum of all numbers in the interval .
Output Format
Output several lines of integers, which are the results of all type 2 operations.
5 5
1 5 4 2 3
2 2 4
1 2 3 2
2 3 4
1 1 5 1
2 1 4
11
8
20
Hint
For 15% of the testdata: , . For 35% of the testdata: , . For 100% of the testdata: , are positive, and the sum of the sequence at any time does not exceed .
Sample Explanation.

Translated by ChatGPT 5
京公网安备 11011102002149号