#C1769. Perform Operations on a List

    ID: 45010 Type: Default 1000ms 256MiB

Perform Operations on a List

Perform Operations on a List

You are given a list of integers of length \( n \) and a sequence of \( q \) operations to perform on the list. The operations are of three types:

  • ADD x: Add the integer \( x \) to every element in the list. (Operation: \( a_i = a_i + x \) for all \( i \))
  • MULTIPLY y: Multiply every element of the list by the integer \( y \). (Operation: \( a_i = a_i \times y \) for all \( i \))
  • REPLACE i z: Replace the element at index \( i \) with \( z \). Note that the index \( i \) is 0-indexed.

Your task is to compute the final state of the list after performing all operations in the given order.

inputFormat

The first line contains two integers \( n \) and \( q \) separated by space. The second line contains \( n \) space-separated integers representing the initial list. Following this, there are \( q \) lines, each containing a single operation in one of the following formats:

  • ADD x
  • MULTIPLY y
  • REPLACE i z

It is guaranteed that for a REPLACE operation, the index \( i \) is valid (i.e., \( 0 \leq i < n \)).

outputFormat

Output a single line containing the \( n \) integers of the final list separated by spaces.

## sample
5 1
1 2 3 4 5
ADD 3
4 5 6 7 8