#K37552. Integer List Manager
Integer List Manager
Integer List Manager
You are given an integer list of size (n) initially filled with zeros. You need to perform (q) queries on the list. There are two types of queries:
-
Add Query:
2 s t x
- Add an integer (x) to every element in the subarray from index (s) to (t) (both inclusive). This operation can be written in LaTeX as: (a_i = a_i + x ; \text{for} ; s \le i \le t). -
Maximum Query:
3 s t
- Output the maximum value among the elements in the subarray from index (s) to (t) (both inclusive). In LaTeX: (\max{a_s, a_{s+1}, \ldots, a_t}).
Input is read from stdin
and the output for each maximum query is printed on a new line to stdout
.
inputFormat
The first line contains two space-separated integers (n) and (q), representing the number of elements in the list and the number of queries respectively. The following (q) lines each represent a query. For an add query, the format is: 2 s t x
(where (s) and (t) are the start and end indices and (x) is the value to be added). For a maximum query, the format is: 3 s t
(where (s) and (t) are the start and end indices for which the maximum is to be retrieved). Indices are zero-based.
outputFormat
For each query of type 3, output the maximum value in the specified subarray on a new line.## sample
6 6
2 0 2 3
2 1 4 -1
3 0 5
3 1 3
2 2 5 2
3 2 4
3
2
4
</p>