#K10951. Segment Tree Range Update and Query

    ID: 23360 Type: Default 1000ms 256MiB

Segment Tree Range Update and Query

Segment Tree Range Update and Query

You are given an array \(A\) of \(n\) integers and \(q\) queries. There are two types of queries:

  • Update Query: Given indices \(l\) and \(r\) and an integer \(x\), update all elements \(A[l], A[l+1], \dots, A[r]\) to the value \(x\). The update is performed using a segment tree.
  • Query: Given indices \(l\) and \(r\), output the maximum value in the subarray \(A[l], A[l+1], \dots, A[r]\).

The indices in the queries are 1-based. In the underlying segment tree, each leaf node corresponds to an element \(A[i]\) and is stored at index \(i+n\) (i.e. \(i_{leaf} = i+n\)). Each internal node holds the maximum of its two children. For a given range \([l, r]\), the query is performed by converting these indices into the segment tree index range and processing until the full segment is covered.

Your task is to process all queries and output the answer for each maximum query.

inputFormat

The input is given from stdin in the following format:

 n q
 A[1] A[2] ... A[n]
 query_1
 query_2
 ...
 query_q

Each query is represented in one line:

  • If the query is of type 1 (update), it is given as: 1 l r x (update the range \(l\) to \(r\) with value \(x\)).
  • If the query is of type 2 (maximum query), it is given as: 2 l r (output the maximum value in the range \(l\) to \(r\)).

outputFormat

For each query of type 2, output the result on a separate line to stdout.

## sample
5 4
1 2 3 4 5
2 1 5
1 2 4 10
2 1 5
2 2 4
5

10 10

</p>