#C6061. Barbarian Game
Barbarian Game
Barbarian Game
Tarzan has organized a game for the barbarians. Initially, each barbarian is assigned a value. The game consists of q rounds, where in each round you will either update the value of a barbarian or answer a query.
For an update round, the operation is represented as 1 x v
, which means update the value of the barbarian at position x (1-indexed) to v.
For a query round, the operation is represented as 2 l r
, which means compute the sum of the values of the barbarians from index l to index r (both inclusive). This can be expressed mathematically as:
\( S = \sum_{i=l}^{r} a_i \)
Your task is to process the rounds and print the result of each query.
inputFormat
The first line contains two integers n and q — the number of barbarians and the number of rounds.
The second line contains n integers, representing the initial values assigned to the barbarians.
Each of the next q lines contains an operation in one of the following two formats:
1 x v
: Update the value of the barbarian at position x to v.2 l r
: Query the sum of values from position l to r.
It is guaranteed that the positions are 1-indexed.
outputFormat
For each query operation, print the resulting sum on a new line. If there are no query operations, do not print anything.
## sample5 3
1 2 3 4 5
2 1 3
1 3 10
2 1 3
6
13
</p>