#P1483. Sequence Update Queries

    ID: 14769 Type: Default 1000ms 256MiB

Sequence Update Queries

Sequence Update Queries

You are given a sequence of n integers \(a_1, a_2, \ldots, a_n\). You need to process m queries on this sequence. There are two types of queries:

  1. Query of the form 1 x y: For every positive integer \(k\) such that \(k \cdot x \le n\), add y to \(a_{kx}\). In mathematical terms, update \(a_{kx} = a_{kx} + y\) for all \(k\) satisfying \(kx\le n\).
  2. Query of the form 2 j: Output the current value of \(a_j\).

The problem requires you to perform these operations in the order they are given and output the answer for each query of the second type.

inputFormat

The first line contains two integers n and m representing the number of elements in the sequence and the number of queries respectively.

The second line contains n space-separated integers, representing the initial values of the sequence \(a_1, a_2, \ldots, a_n\).

The following m lines each contain a query in one of the following formats:

  • 1 x y: Add y to every element \(a_{kx}\) for all positive integers \(k\) such that \(kx \le n\).
  • 2 j: Output the value of \(a_j\).

outputFormat

For every query of the second type, output the corresponding value of \(a_j\) on a new line.

sample

5 5
1 2 3 4 5
2 3
1 2 3
2 4
1 1 -2
2 1
3

7 -1

</p>