#C639. Segment Tree Maximum Query
Segment Tree Maximum Query
Segment Tree Maximum Query
In this problem, you are given a sequence of integers and queries. There are two types of queries:
- Update query: Given in the format
1 i x
, update the value at position (1-indexed) in the array to . - Query query: Given in the format `2 l r$, output the maximum value in the subarray from index $lr$ (inclusive).
You are required to efficiently process these queries. A typical solution is to use a segment tree data structure which allows both update and maximum range query in time. The segment tree is constructed using the formula
for non-leaf nodes. Please note that the array indices in the input are 1-indexed, so be sure to convert them appropriately when implementing your solution.
inputFormat
The input is read from standard input and has the following format:
- The first line contains two integers and , representing the number of elements in the sequence and the number of queries, respectively.
- The second line contains integers, the initial elements of the sequence.
- Each of the next lines contains three integers. If the first integer is , the line represents an update operation in the form
1 i x
. If the first integer is , the line represents a range query in the form2 l r
.
outputFormat
For each query of type 2, output the maximum value in the subarray from index to on a separate line to standard output.## sample
5 5
1 2 3 4 5
2 1 3
1 2 10
2 1 3
2 2 5
1 4 7
3
10
10
</p>