#K1516. Efficient List Manager

    ID: 24295 Type: Default 1000ms 256MiB

Efficient List Manager

Efficient List Manager

You are given a list of N integers and need to perform Q operations on this list. The operations are provided as commands, and each command can be one of the following types:

  • sum l r: Calculate the sum of the elements from index l to r (inclusive).
  • min l r: Find the minimum element from index l to r (inclusive).
  • update i x: Update the element at index i to value x.
  • multiply l r x: Multiply each element from index l to r (inclusive) by x.

After processing all commands, you should output the results of the sum and min operations in the order they appear. The indices are 1-based.

Note: Commands that update or multiply values do not produce an output directly. Their effect is cumulative and may affect subsequent queries.

The mathematical representation for the operations can be summarized by the following formulas:

  • Sum operation: \(S = \sum_{i=l}^{r} a_i\)
  • Minimum operation: \(m = \min\{a_l, a_{l+1}, \dots, a_r\}\)

inputFormat

The input is given in the following format:

N Q
a1 a2 ... aN
command1
command2
...
commandQ

Where:

  • N (\(1 \leq N \leq 10^5\)) is the number of elements in the list.
  • Q (\(1 \leq Q \leq 10^5\)) is the number of commands.
  • The second line contains N space-separated integers.
  • Each of the next Q lines contains one command in one of the following forms:
    sum l r, min l r, update i x, or multiply l r x

outputFormat

For each sum and min command, output the result on a separate line in the order the commands appear.

## sample
5 1
1 2 3 4 5
sum 1 3
6