#C8301. Magical Strength Queries
Magical Strength Queries
Magical Strength Queries
You are given a sequence of magical strengths of n steps. You need to process q queries of two possible types:
- Update Query: Given
1 x y
, update the magical strength at the x-th step to y. - Sum Query: Given
2 l r
, compute the sum of magical strengths between the l-th and r-th steps (inclusive). In mathematical terms, compute $$\sum_{i=l}^{r} a_i.$$
The input is given in the following format, and all indices are 1-indexed. Your task is to perform the queries in order and output the result for each sum query.
inputFormat
The first line contains two integers n
and q
, denoting the number of steps and the number of queries, respectively.
The second line contains n
space-separated integers representing the initial magical strengths.
Each of the next q
lines contains three integers. The first integer indicates the type of the query:
- If it is
1
, then the next two integersx
andy
indicate that the strength at the x-th step should be updated toy
. - If it is
2
, then the next two integersl
andr
indicate that you need to compute the sum of strengths from indexl
tor
(inclusive).
outputFormat
For each query of type 2
, output the computed sum on a separate line in the order the queries appear.
5 4
5 -3 6 2 -1
2 2 4
1 3 -5
2 1 5
2 3 5
5
-2
-4
</p>