#C7183. Inventory Tracking System

    ID: 51026 Type: Default 1000ms 256MiB

Inventory Tracking System

Inventory Tracking System

Alice owns a bakery and needs an efficient system to track inventory changes for various types of pastries. Initially, she stocks (n) types of pastries with known quantities, and then she performs (q) update operations. Each update is either:

  1. Adding a quantity (x) to the (i)-th pastry (update type 1), or
  2. Setting the stock of the (i)-th pastry directly to (x) (update type 2).

After each update, the system must output the total quantity of pastries currently in stock. Your task is to implement this system based on the inputs provided through standard input (stdin) and output the results to standard output (stdout).

inputFormat

The first line contains two integers (n) and (q) — the number of pastry types and the number of update operations, respectively. The second line contains (n) space-separated integers representing the initial stock for each pastry type. Then, (q) lines follow, each containing three integers:

(t) (i) (x)

  • If (t = 1): add (x) to the stock of the (i)-th pastry.
  • If (t = 2): set the stock of the (i)-th pastry to (x).

Note: (i) is 1-indexed.

outputFormat

Output (q) lines. Each line should display the total number of pastries in stock after performing the corresponding update.## sample

4 4
10 20 30 40
1 2 10
2 3 5
1 4 20
2 1 15
110

85 105 110

</p>