#K6146. Inventory Management
Inventory Management
Inventory Management
You are given an inventory of n products with their initial stock levels. You need to process q queries. There are two types of queries:
- update p x: Increase the stock of product p by x units. (Note: products are numbered from 1 to n.)
- query p: Output the current stock level of product p.
The input starts with two integers n and q, followed by a line with n integers representing the initial stock levels. Then, there are q lines each representing a query.
Input Format:
n q s1 s2 ... sn query/update queries
Output Format: For each query of type "query", output the result in a separate line.
In mathematical terms, if we let Si be the stock for the i-th product, then an update operation on product p is: \[ S_p \leftarrow S_p + x \] and a query returns S_p.
inputFormat
The first line contains two integers n
and q
— the number of products and the number of queries respectively.
The second line contains n
integers where the i
-th integer represents the initial stock for the product i
.
Each of the following q
lines contains a query in one of the following two formats:
update p x
— addx
to the stock of productp
.query p
— output the current stock of productp
.
outputFormat
For each query of type query
, output a single line containing the current stock level of the specified product.
5 7
20 10 5 0 15
query 3
update 1 5
query 1
update 5 10
query 5
update 2 20
query 2
5
25
25
30
</p>