#C2984. Sales Transactions Manager
Sales Transactions Manager
Sales Transactions Manager
You are given an initial list of sales transaction amounts. Your task is to implement a data structure that supports the following operations:
- Insert Operation: Insert a transaction amount at a given 0-indexed position.
- Update Operation: Update the transaction amount at a given 0-indexed position.
- Range Sum Query: Calculate the sum of transaction amounts from index \(l\) to \(r\) (both inclusive). That is, compute \(\sum_{i=l}^{r} a_i\).
The operations are given sequentially in the input. Perform these operations and for every range sum query, output the result.
inputFormat
The input is given in the following format from stdin:
n q a1 a2 ... an op1 x y op2 x y ... (q operations)
Here, n
is the number of initial transactions and q
is the number of operations. The next line contains n
space-separated integers representing the initial transaction amounts. Each of the following q
lines contains an operation in one of the following formats:
0 pos amount
: Insertamount
at positionpos
.1 pos new_amount
: Update the transaction at positionpos
to benew_amount
.2 l r
: Output the sum of transactions from indexl
to indexr
(inclusive).
outputFormat
For each range sum query (operation type 2), output the resulting sum on a new line to stdout.
## sample5 1
100 200 300 400 500
2 1 3
900
</p>