#P3372. 【模板】线段树 1

【模板】线段树 1

Description

As stated, given a sequence {ai}\{a_i\}, you need to perform the following two operations:

  1. Add kk to every number in a given interval.
  2. Find the sum of all numbers in a given interval.

Input Format

The first line contains two integers n,mn, m, representing the number of elements in the sequence and the total number of operations.

The second line contains nn space-separated integers aia_i, where the ii-th integer is the initial value of the ii-th element.

Each of the next mm lines contains 33 or 44 integers representing an operation, as follows:

  1. 1 x y k: add kk to every number in the interval [x,y][x, y].
  2. 2 x y: output the sum of all numbers in the interval [x,y][x, y].

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: n8n \le 8, m10m \le 10. For 35% of the testdata: n103n \le {10}^3, m104m \le {10}^4. For 100% of the testdata: 1n,m1051 \le n, m \le {10}^5, ai,ka_i, k are positive, and the sum of the sequence at any time does not exceed 2×10182\times 10^{18}.

Sample Explanation.

Translated by ChatGPT 5