#C391. Warehouse Box Operations
Warehouse Box Operations
Warehouse Box Operations
You are managing a warehouse with n boxes, each containing a certain number of items. Your task is to process q operations on these boxes. There are three types of operations:
- Add Operation (Type 1): Add y items to the x-th box.
- Remove Operation (Type 2): Remove y items from the x-th box.
- Report Operation (Type 3): Report the current number of items in the x-th box.
The boxes are indexed from 1 to n. For any valid box index \( x \), the operations modify the box as follows:
- For an add operation: \( items[x-1] = items[x-1] + y \).
- For a remove operation: \( items[x-1] = items[x-1] - y \).
After processing all operations, output the results of all report operations in the order they appear.
inputFormat
The first line of input contains two integers n and q, representing the number of boxes and the number of operations respectively.
The second line contains n space-separated integers indicating the initial number of items in each box.
The following q lines each represent an operation in one of the following formats:
- For add and remove operations (types 1 and 2):
op x y
- For report operations (type 3):
op x
Here, op
is the operation type (1, 2, or 3), x
is the box index (1-indexed), and y
is the number of items to add or remove (only present for types 1 and 2).
outputFormat
For each report operation (type 3), output the current number of items in the specified box on a new line.
## sample5 5
2 3 5 1 4
1 3 2
3 3
2 2 1
3 2
3 4
7
2
1
</p>