#C8766. Array Operations
Array Operations
Array Operations
You are given an array of integers and a series of queries. There are two types of queries:
- Update Query:
1 x y
— update the value at index \( x \) to \( y \). - Sum Query:
2 l r
— output the sum of the subarray from index \( l \) to \( r \) (both inclusive).
The array is 1-indexed. It is guaranteed that the queries are processed in the given order. For every sum query, you should print the sum on a new line.
Input Format: The first line contains two integers \( n \) and \( q \) where \( n \) is the number of elements in the array and \( q \) is the number of queries.
The second line contains \( n \) space-separated integers representing the array.
Each of the following \( q \) lines contains a query in one of the following two forms:
1 x y
for an update operation2 l r
for a sum query
inputFormat
The input is read from standard input with the following format:
- The first line contains two integers \( n \) and \( q \).
- The second line contains \( n \) space-separated integers representing the array.
- The next \( q \) lines each contain a query in one of the two forms:
1 x y
(update) or2 l r
(sum query).
outputFormat
For each query of type 2
, output one line containing the sum of the subarray from index \( l \) to \( r \) after all previous operations have been performed.
5 3
1 2 3 4 5
2 1 3
1 2 10
2 1 3
6
14
</p>