#K13981. Marathon Checkpoints Participant Updates

    ID: 24033 Type: Default 1000ms 256MiB

Marathon Checkpoints Participant Updates

Marathon Checkpoints Participant Updates

You are given n checkpoints of a marathon, each with an initial number of participants. A total of q updates are to be processed sequentially. Each update is in one of the two forms:

  • 1 i x: meaning x participants join the checkpoint i.
  • 2 i x: meaning x participants withdraw from checkpoint i.

After processing each update, output the updated number of participants at the checkpoint specified in that update. Note that the updates are applied in order and the state carries over between updates.

The operation can be formalized as follows:

[ participants[i] = \begin{cases} participants[i] + x & \text{if the update is } 1\ i\ x, \ participants[i] - x & \text{if the update is } 2\ i\ x. \end{cases} ]

inputFormat

The input is read from the standard input and has the following format:

n q
p1 p2 ... pn
op1 i1 x1
op2 i2 x2
... 
opq iq xq

Where:

  • n is the number of checkpoints.
  • q is the number of update queries.
  • The second line contains n integers representing the initial number of participants at each checkpoint.
  • Each of the next q lines contains three integers: op, i, x where op is either 1 (for joining) or 2 (for withdrawal).

outputFormat

For each update query, output a single line containing the updated number of participants at the affected checkpoint.

## sample
5 6
10 20 30 40 50
1 3 5
2 2 10
1 5 20
2 4 15
1 1 10
2 3 10
35

10 70 25 20 25

</p>