#P6242. 【模板】线段树 3(区间最值操作、区间历史最值)
【模板】线段树 3(区间最值操作、区间历史最值)
Background
This problem is a template for using a segment tree to maintain range maximum-related operations and the range historical maximum.
Problem Description
Given a sequence of length , we also define an auxiliary array . Initially, is exactly the same as . Then operations are performed. There are five types of operations, given in the following format:
1 l r k: For all , add to ( can be negative).2 l r v: For all , set to .3 l r: Compute .4 l r: For all , compute the maximum value of .5 l r: For all , compute the maximum value of .
After each operation, we perform an update: .
Input Format
The first line contains two positive integers , representing the length of sequence and the number of operations.
The second line contains integers , representing the sequence .
The next lines each start with an integer , representing the operation type. It is followed by two or three integers as the operation parameters. The format is described in the Description section.
Output Format
For operations with , output one line containing one integer, which is the answer to the query.
5 6
1 2 3 4 5
3 2 5
1 1 3 3
4 2 4
2 3 4 1
5 1 5
3 1 4
14
6
6
11
Hint
Sample Explanation #1
| Operation Count | Input | Operation | Sequence | Output |
|---|---|---|---|---|
| 0 | ||||
| 1 | 3 2 5 |
Find the sum of all numbers in | 14 |
|
| 2 | 1 1 3 3 |
Add to all numbers in | ||
| 3 | 4 2 4 |
Find the maximum of all numbers in | 6 |
|
| 4 | 2 3 4 1 |
Replace all numbers in with the minimum of itself and | ||
| 5 | 5 1 5 |
Find the maximum among the historical maximum values over | 6 |
|
| 6 | 3 1 4 |
Find the sum of all numbers in | 11 |
|
Constraints
- For test points , .
- For test points , .
- For test points , .
- For all testdata, it is guaranteed that , , , , , and .
Note
The input size of this problem is large. Please use a reasonable and efficient input method.
Translated by ChatGPT 5