#C3176. Price Tracker and Query Handler
Price Tracker and Query Handler
Price Tracker and Query Handler
You are given n products with initial prices and m operations over several days. Each operation is one of the following:
- Update: Change the price of a product to a given value.
- Query: Report the total cost of all products.
The update operation is represented as 1 p v, which means update the price of the p-th product to v. The query operation is represented as 2.
Formally, initially you have an array \(A = [a_1, a_2, \dots, a_n]\). Then for each operation:
- If the operation is \(1\ p\ v\), update \(a_p = v\).
- If the operation is \(2\), output \(\sum_{i=1}^{n} a_i\).
Process all operations in the given order and output the answer for each query.
inputFormat
The input is read from stdin and has the following format:
n m a1 a2 ... an op1 op2 ... op_m
Here, n is the number of products and m is the number of operations. The next line contains n integers denoting the initial prices of the products. Then follow m lines each representing an operation. Each operation is either:
1 p vfor an update operation, or2for a query operation.
outputFormat
For each query operation (operation type 2), output the total cost of all products on a separate line to stdout.
5 3
1 2 3 4 5
2
1 3 10
215
22
</p>