#P76. [CSP-S 2020] Database Optimization

[CSP-S 2020] Database Optimization

Person in Charge

Problem Description

Functions are a crucial concept in various programming languages. With the help of functions, we can always decompose complex tasks into relatively simple subtasks, breaking them down into extremely simple basic operations until they are fully refined. This makes the code structure more rigorous and organized. However, an excessive number of function calls can also lead to additional overhead and affect the runtime efficiency of the program.

A database application provides several functions for maintaining data. It is known that the functions can be classified into three types based on their functionality:

  1. Add a specific value to a designated element in the data;
  2. Multiply every element in the data by the same value;
  3. Execute several function calls in sequence, with no recursion allowed (i.e., the function will not call itself directly or indirectly).

When using this database application, the user can input a sequence of functions to be called at once (a function may be called multiple times). After executing the functions in the sequence in order, the data in the system is updated. One day, User A encountered difficulties while using this database program to process data: due to frequent and inefficient function calls, the system became unresponsive during execution, and he had to forcefully terminate the database program. To calculate the correct data, User A consulted the software documentation to learn the specific functional information of each function. Now he wants you to help him calculate the updated data based on this information.

Input Format

The first line contains a positive integer nn, representing the number of data elements.
The second line contains nn integers, where the ii-th integer denotes the initial value of the data element with index ii as aia_i.
The third line contains a positive integer mm, representing the number of functions provided by the database application. The functions are numbered from 11 to mm.
For the next mm lines, the first integer in the jj-th line (1jm1 \le j \le m) is TjT_j, indicating the type of the jj-th function:

  1. If Tj=1T_j = 1, the next two integers PjP_j and VjV_j respectively represent the index of the element to which the addition is performed and the value to be added;
  2. If Tj=2T_j = 2, the next integer VjV_j represents the value by which all elements are multiplied;
  3. If Tj=3T_j = 3, the next positive integer CjC_j represents the number of functions to be called by the jj-th function, followed by CjC_j integers g1(j),g2(j),,gCj(j)g^{(j)}_1, g^{(j)}_2, \ldots, g^{(j)}_{C_j} which denote the numbers of the functions to be called in sequence.

The (m+4)(m + 4)-th line contains a positive integer QQ, representing the length of the input function operation sequence.
The (m+5)(m + 5)-th line contains QQ integers fif_i, where the ii-th integer denotes the number of the function to be executed as the ii-th step.

Output Format

Output a line of nn integers separated by spaces, in the order of indices 11 to nn, representing the value of each element in the database after executing the input function sequence. The answer should be taken modulo 998244353\boldsymbol{998244353}.

Samples

3
1 2 3
3
1 1 1
2 2
3 2 1 2
2
2 3
6 8 12

Sample 1 Explanation

Function 1 is used to add 1 to the value of a1a_1. Function 2 is used to multiply all elements by 2. Function 3 first calls Function 1, then calls Function 2.

The final function sequence first executes Function 2, changing the values of all elements to 2,4,62, 4, 6.

When executing Function 3 next, it first calls Function 1, changing the values of all elements to 3,4,63, 4, 6. Then it calls Function 2, changing the values of all elements to 6,8,126, 8, 12.

Sample 2

See call/call2.in and call/call2.ans in the contestant's directory.

Sample 3

See call/call3.in and call/call3.ans in the contestant's directory.

Data Range

Test Case ID n,m,Qn, m, Q \le Cj\sum C_j Other Special Restrictions
121 \sim 2 10001000 =m1= m - 1 The function call relationship forms a tree
343 \sim 4 100\le 100 None
565 \sim 6 2000020000 40000\le 40000 No Type 2 functions or no Type 1 functions
77 =0= 0 None
898 \sim 9 =m1= m - 1 The function call relationship forms a tree
101110 \sim 11 2×105\le 2 \times 10^5 None
121312 \sim 13 10510^5 No Type 2 functions or no Type 1 functions
1414 =0= 0 None
151615 \sim 16 =m1= m - 1 The function call relationship forms a tree
171817 \sim 18 5×105\le 5 \times 10^5 None
192019 \sim 20 106\le 10^6

For all test cases: 0ai1040 \le a_i \le 10^4, Tj{1,2,3}T_j \in \{1,2,3\}, 1Pjn1 \le P_j \le n, 0Vj1040 \le V_j \le 10^4, 1gk(j)m1 \le g^{(j)}_k \le m, 1fim1 \le f_i \le m.