#K60072. Taco Array Operations

    ID: 31005 Type: Default 1000ms 256MiB

Taco Array Operations

Taco Array Operations

You are given an array of n integers and a sequence of q operations. The operations are of three types:

  • add x: Add an integer x to a running addition accumulator.
  • mult x: Multiply both the current addition accumulator and a running multiplication accumulator by x.
  • get i: Retrieve the value at index i of the initial array after applying all operations so far. The value is computed using the formula: $$result = a_i \times m + d,$$ where m is the cumulative multiplication factor and d is the cumulative addition.

Initially, the cumulative factors are set to \( m = 1 \) and \( d = 0 \). Process each query in order and output the result for each get operation. The i provided in a get operation is zero-indexed.

inputFormat

The first line contains two integers n and q representing the size of the array and the number of operations respectively.

The second line contains n space-separated integers, representing the initial array.

Each of the next q lines contains an operation in one of the following formats:

  • add x
  • mult x
  • get i

All values x and indices i are integers, and indices are zero-based.

outputFormat

For each get operation, output the computed result on a separate line.

## sample
5 4
1 2 3 4 5
add 2
mult 3
get 2
get 4
15

21

</p>