#C2762. Sequence Query Processor

    ID: 46114 Type: Default 1000ms 256MiB

Sequence Query Processor

Sequence Query Processor

You are given two sequences: sequence A and sequence B. Initially, sequence A is defined as \(A = [1, 2, \dots, N]\) and sequence B is provided as input. You are to process a series of \(Q\) queries. All indices are 1-indexed.

The queries can be of the following types:

  • Type 1: 1 l r — Output the sum \(\sum_{i=l}^{r} A_i\).
  • Type 2: 2 l r — For every index \(i\) from \(l\) to \(r\), update \(A_i = B_i\).
  • Type 3: 3 l r x — For every index \(i\) from \(l\) to \(r\), update \(B_i = x\) (i.e. assign a constant value \(x\)).
  • Type 4: 4 l r x — For every index \(i\) from \(l\) to \(r\), update \(A_i = A_i \times x\) (i.e. multiply by \(x\)).

Your task is to execute these queries in sequence. For each query of type 1, output the computed sum on a new line.

inputFormat

The input is given in the following format through standard input (stdin):

  1. The first line contains two integers \(N\) and \(Q\), representing the length of the sequences and the number of queries, respectively.
  2. The second line contains \(N\) space-separated integers representing the initial sequence B.
  3. The next \(Q\) lines each describe a query. Each query starts with an integer denoting the query type. The parameters for each query type are as follows:
    • Type 1: 1 l r
    • Type 2: 2 l r
    • Type 3: 3 l r x
    • Type 4: 4 l r x

outputFormat

For each query of type 1, output the sum of the corresponding segment of sequence A on a separate line. The output should be written to standard output (stdout).

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

</p>