#P7077. Database Function Sequence Execution

    ID: 20283 Type: Default 1000ms 256MiB

Database Function Sequence Execution

Database Function Sequence Execution

This problem simulates the execution of a sequence of function calls on a database's data array. In many programming languages, functions allow us to break down complex tasks into simpler operations. However, too many function calls can slow down the system. Here, the database provides three types of functions to update data:

  • Type 1: Add Operation – Format: 1 i x. This operation adds an integer x to the i-th element of the array (1-indexed). In latex: $a_i \leftarrow a_i + x$.
  • Type 2: Multiply Operation – Format: 2 x. This operation multiplies every element in the array by an integer x. In latex: $a_i \leftarrow a_i \times x$ for all valid i.
  • Type 3: Sequence Operation – Format: 3 k followed by k function calls. The operations within a sequence are executed sequentially. Note that functions do not recur (i.e. no direct or indirect self-calls).

Initially, you are given an array of integers. Then a sequence of function calls is provided. After executing these operations, output the final state of the array with the elements separated by a single space.

inputFormat

The input consists of multiple parts:

  1. An integer n representing the number of elements in the array.
  2. n space-separated integers representing the initial state of the array.
  3. An integer q representing the number of top-level function calls.
  4. q function call descriptions. Each function call is one of the following formats:
    • Type 1: 1 i x – add x to the i-th element (1-indexed).
    • Type 2: 2 x – multiply every element by x.
    • Type 3: 3 k – a sequence operation, followed by k function calls (which can be nested recursively).

It is guaranteed that the sequence is structured such that no function call eventually calls itself (directly or indirectly).

outputFormat

Output the final state of the array on a single line. The elements must be separated by a single space.

sample

3
1 2 3
2
1 2 5
2 3
3 21 9