#P4146. Segment Operations with Reversal and Range Maximum Query
Segment Operations with Reversal and Range Maximum Query
Segment Operations with Reversal and Range Maximum Query
You are given a sequence of length \( N \) where initially every element is 0. You need to handle \( Q \) operations on the sequence. There are three types of operations:
- Type 1: For given indices \( L \) and \( R \) and an integer \( V \), add \( V \) to every element in the segment \( [L, R] \). This can be denoted as \( a_i = a_i + V \) for every \( i \) where \( L \leq i \leq R \).
- Type 2: For given indices \( L \) and \( R \), reverse the segment \( [L, R] \). For example, the sequence
1 2 3 4
becomes4 3 2 1
when the entire segment is reversed. - Type 3: For given indices \( L \) and \( R \), output the maximum value in the segment \( [L, R] \).
You are to process the \( Q \) operations in order and output the result for each type 3 query.
inputFormat
The first line contains two integers \( N \) and \( Q \), where \( N \) is the length of the sequence and \( Q \) is the number of operations.
Each of the following \( Q \) lines describes an operation in one of the following formats:
- For type 1:
1 L R V
- For type 2:
2 L R
- For type 3:
3 L R
Note that the sequence is 1-indexed and initially all elements are 0.
outputFormat
For each operation of type 3, output a single line containing the maximum value in the segment \( [L, R] \).
sample
5 5
1 1 5 3
3 1 5
2 2 4
3 1 5
3 2 4
3
3
3
</p>