#P7077. [CSP-S 2020] 函数调用

    ID: 8004 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP数学2020拓扑排序CSP-S 提高级

[CSP-S 2020] 函数调用

Problem Description

Functions are an important concept in many programming languages. With functions, we can always break a complex task into relatively simple subtasks, until they are refined into very simple basic operations, making the code more rigorous and well-organized. However, too many function calls can also cause extra overhead and affect the program’s running efficiency.

A database application provides several functions to maintain data. These functions can be divided into three types:

  1. Add a value to a specified element in the data.
  2. Multiply every element in the data by the same value.
  3. Execute several function calls in order, and it is guaranteed that no recursion will occur (i.e., it will not directly or indirectly call itself).

When using this database application, the user can input, at one time, a sequence of functions to call (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, Xiao A ran into trouble while using this database program to process data: due to frequent and inefficient function calls, the system became unresponsive during execution, so he had to force-quit the database program. In order to compute the correct data, Xiao A consulted the software documentation and learned the detailed information of each function. Now he asks you to compute what the updated data should be based on this information.

Input Format

The first line contains a positive integer nn, denoting the number of data elements.
The second line contains nn integers. The ii-th integer indicates that the initial value of the data at index ii is aia_i.
The third line contains a positive integer mm, denoting the number of functions provided by the database application. The functions are numbered from 1m1 \sim m.
In the next mm lines, in the jj-th line (1jm1 \le j \le m), the first integer is TjT_j, denoting the type of function jj:

  1. If Tj=1T_j = 1, the next two integers Pj,VjP_j, V_j denote the index of the element to be added and the value to add to it, respectively.
  2. If Tj=2T_j = 2, the next integer VjV_j denotes the multiplier applied to all elements.
  3. If Tj=3T_j = 3, the next positive integer CjC_j denotes the number of functions called by function jj,
    followed by CjC_j integers g1(j),g2(j),,gCj(j)g^{(j)}_1, g^{(j)}_2, \ldots , g^{(j)}_{C_j} in order, denoting the function numbers it calls.

Line m+4m + 4 contains a positive integer QQ, denoting the length of the input function operation sequence.
Line m+5m + 5 contains QQ integers fif_i. The ii-th integer denotes the function number of the ii-th executed function.

Output Format

Output one line containing nn integers separated by spaces. In the order of indices 1n1 \sim n, output the value of each element in the database after executing the input function sequence. Take the answer modulo 998244353\boldsymbol{998244353}.

3
1 2 3
3
1 1 1
2 2
3 2 1 2
2
2 3

6 8 12
10
1 2 3 4 5 6 7 8 9 10
8
3 2 2 3
3 2 4 5
3 2 5 8
2 2
3 2 6 7
1 2 5
1 7 6
2 3
3
1 2 3
36 282 108 144 180 216 504 288 324 360

见附件中的 call/call3.in
见附件中的 call/call3.ans

Hint

[Sample #1 Explanation]

Function 11 adds 11 to a1a_1. Function 22 multiplies all elements by 22. Function 33 first calls function 11, then calls function 22.

The final function sequence first executes function 22, so all elements become 2,4,62, 4, 6.

Then when executing function 33, it first calls function 11, so all elements become 3,4,63, 4, 6. Then it calls function 22, so all elements become 6,8,126, 8, 12.

[Constraints]

::cute-table{tuack}

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

For all testdata: 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

Translated by ChatGPT 5