#C9505. Array Modification Operations

    ID: 53606 Type: Default 1000ms 256MiB

Array Modification Operations

Array Modification Operations

You are given an array of N integers and a sequence of M operations. Each operation is represented as a pair: an operation type and an integer. The operation type can be either 'A' or 'M'.

For an operation of type 'A', you must add the given integer to every element in the array. For an operation of type 'M', you must multiply every element in the array by the given integer.

Formally, if the original element is (a_i) and the operation is (op) with parameter (x), then after applying the operation:

  • If (op = A), then (a_i \leftarrow a_i + x).
  • If (op = M), then (a_i \leftarrow a_i \times x).

Apply all M operations in the given order and output the final state of the array. This problem tests your ability to iteratively modify arrays based on sequential operations.

inputFormat

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

  • The first line contains an integer (N), representing the number of elements in the array.
  • The second line contains (N) space-separated integers, representing the initial array.
  • The third line contains an integer (M), representing the number of operations.
  • The following (M) lines each contain an operation. Each operation consists of a character and an integer separated by a space. The character is either 'A' (for addition) or 'M' (for multiplication).

outputFormat

Output a single line to standard output (stdout) containing the modified array after all operations have been performed. The elements should be printed in order and separated by a single space.## sample

5
2 3 5 7 11
3
A 2
M 2
A 1
9 11 15 19 27