#K66417. Sequence Queries
Sequence Queries
Sequence Queries
You are given a sequence of n integers and q queries. The queries are of two types:
- Update Query (Type 1): Update the element at position x (1-indexed) to a new value y. In mathematical notation, if the original sequence is \(A = [a_1, a_2, \dots, a_n]\), then after an update at index \(x\), \(a_x = y\).
- Range Sum Query (Type 2): Calculate the sum of the elements in the subarray from index l to index r (inclusive). Formally, compute \(\sum_{i=l}^{r} a_i\).
Process all queries in the order given. For each range sum query (Type 2), output the computed sum on a separate line.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two integers
n
andq
, wheren
is the number of elements in the sequence andq
is the number of queries. - The second line contains
n
space-separated integers representing the initial sequence. - The next
q
lines each represent a query in one of the following formats:- For an update query:
1 x y
(update the element at indexx
toy
). - For a range sum query:
2 l r
(calculate the sum from indexl
tor
inclusive).
- For an update query:
outputFormat
For each range sum query (Type 2), output a single integer in a separate line, which is the sum of the elements in the specified range.
## sample5 5
1 2 3 4 5
2 1 3
1 3 10
2 1 3
2 3 5
1 5 20
6
13
19
</p>