#K1281. Stock Price Manager

    ID: 23773 Type: Default 1000ms 256MiB

Stock Price Manager

Stock Price Manager

In this problem, you are required to manage a sequence of daily stock prices and perform a series of queries. Initially, you are given an array representing the stock prices on consecutive days. You must then process a series of operations of three types:

  1. update d p: Update the stock price on day ( d ) to ( p ).
  2. maxRange l r: Report the maximum stock price in the range from day ( l ) to day ( r ) (inclusive).
  3. minRange l r: Report the minimum stock price in the range from day ( l ) to day ( r ) (inclusive).

The challenge is to correctly implement these operations and ensure that your solution processes a sequence of commands from ( stdin ) and writes the appropriate outputs to ( stdout ) for the queries. The operations must handle updates and queries dynamically.

Note: Days are 1-indexed. All formulas or mathematical notations, such as ranges and indices, should be interpreted in the conventional programming sense where the first day is day 1.

inputFormat

The input is read from standard input (stdin) and has the following format:

The first line contains two integers ( n ) and ( q ), representing the number of days (i.e., the length of the stock prices array) and the number of queries, respectively.

The second line contains ( n ) space-separated integers, representing the initial stock prices for days ( 1 ) to ( n ).

Each of the following ( q ) lines contains a query in one of the following forms:

  • For updating a price: update d p where ( d ) is the 1-indexed day and ( p ) is the new price.
  • For querying the maximum value in a range: maxRange l r where ( l ) and ( r ) (( l \le r )) denote the inclusive range of days.
  • For querying the minimum value in a range: minRange l r where ( l ) and ( r ) (( l \le r )) denote the inclusive range of days.

outputFormat

For each query of type maxRange or minRange, output the result on a new line to standard output (stdout). There should be no output for the update operations.## sample

5 5
10 5 3 8 6
maxRange 1 5
minRange 1 5
update 3 15
maxRange 1 5
minRange 1 5
10

3 15 5

</p>