#K4316. Perform Operations on Array
Perform Operations on Array
Perform Operations on Array
You are given an array of N integers. Your task is to perform Q operations on this array. There are two types of operations:
- Type 1: Add a given integer X to all elements in the array.
- Type 2: Retrieve the value of the element at a given index i (1-indexed), considering all previous additions.
The operations are applied sequentially. For a type 1 operation, update the array by adding X to every element. For a type 2 operation, output the current value of the element at the specified index.
Note: Use cumulative addition for type 1 operations. Mathematically, if you denote the cumulative addition by \( S \), then whenever you need to retrieve the value of an element \( a_i \), the answer is \( a_i + S \).
inputFormat
The first line contains two integers \( N \) and \( Q \) indicating the number of elements in the array and the number of operations, respectively.
The second line contains \( N \) space-separated integers representing the initial values of the array.
The following \( Q \) lines each contain an operation in one of the following formats:
1 X
— add the integer \( X \) to every element of the array.2 i
— retrieve and print the current value of the element at position \( i \) (1-indexed).
outputFormat
For each type 2 operation, output a single line containing the resulting value after performing all operations up to that point.
## sample5 5
1 2 3 4 5
1 10
2 3
1 -3
2 1
2 5
13
8
12
</p>