#C9937. Maximum Value in Sequence After Operations
Maximum Value in Sequence After Operations
Maximum Value in Sequence After Operations
You are given a sequence of n elements, initially all equal to 0. You will perform q operations on this sequence. Each operation is of one of the following two types:
- Add Operation: For an operation of type 1 formatted as \(1\ l\ r\ x\), add \(x\) to every element from index \(l\) to \(r\) (inclusive).
- Set Operation: For an operation of type 2 formatted as \(2\ l\ r\ y\), set every element from index \(l\) to \(r\) (inclusive) to \(y\).
After processing all operations, output the maximum value present in the sequence. Formally, if the final sequence is \(A = [A_1, A_2, \ldots, A_n]\), you must compute:
\(\max_{1 \le i \le n} A_i\)
The input is provided from stdin and the answer should be output to stdout.
inputFormat
The first line contains two space-separated integers: \(n\) (the number of elements in the sequence) and \(q\) (the number of operations).
The next \(q\) lines each contain an operation in the following format:
- For an add operation:
1 l r x
- For a set operation:
2 l r y
Indices are 1-indexed.
outputFormat
Output a single integer representing the maximum value in the sequence after all operations have been performed.
## sample5 3
1 1 3 5
2 2 4 7
1 3 5 2
9