#K81827. Performing Operations on an Array
Performing Operations on an Array
Performing Operations on an Array
You are given an array of n integers and need to perform q operations on it. There are two types of operations:
- Update Operation: Given three integers \(l\), \(r\) and \(v\), update every element of the array in the index range \([l, r]\) (inclusive) to \(v\). That is, for every index \(i\) with \(l \le i \le r\), set \(a_i = v\).
- Prefix Sum Query: Given two integers \(l\) and \(r\), compute the sum \(\sum_{i=l}^{r} a_i\) of the elements in the array from index \(l\) to index \(r\) (inclusive) and print the result.
Note that the operations are applied sequentially; an update affects subsequent queries.
inputFormat
The input is given via standard input (stdin) and is structured as follows:
- The first line contains an integer \(n\) — the number of elements in the array.
- The second line contains \(n\) space-separated integers — the initial values of the array.
- The third line contains an integer \(q\) — the number of operations to perform.
- The following \(q\) lines each describe an operation. An operation is either:
Update Operation: A line with three integers \(l\), \(r\), and \(v\), meaning update all indices from \(l\) to \(r\) to the value \(v\).
Prefix Sum Query: A line with two integers \(l\) and \(r\), meaning output the sum of the elements from index \(l\) to \(r\).
All indices are zero-indexed.
outputFormat
For each prefix sum query (an operation with two integers), output the computed sum on a separate line via standard output (stdout). If no query operation is provided, no output should be produced.
## sample5
1 2 3 4 5
5
1 3
0 4
2 4 10
0 4
0 2
9
15
33
13
</p>