#P7077. [CSP-S 2020] 函数调用
[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:
- Add a value to a specified element in the data.
- Multiply every element in the data by the same value.
- 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 , denoting the number of data elements.
The second line contains integers. The -th integer indicates that the initial value of the data at index is .
The third line contains a positive integer , denoting the number of functions provided by the database application. The functions are numbered from .
In the next lines, in the -th line (), the first integer is , denoting the type of function :
- If , the next two integers denote the index of the element to be added and the value to add to it, respectively.
- If , the next integer denotes the multiplier applied to all elements.
- If , the next positive integer denotes the number of functions called by function ,
followed by integers in order, denoting the function numbers it calls.
Line contains a positive integer , denoting the length of the input function operation sequence.
Line contains integers . The -th integer denotes the function number of the -th executed function.
Output Format
Output one line containing integers separated by spaces. In the order of indices , output the value of each element in the database after executing the input function sequence. Take the answer modulo .
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 adds to . Function multiplies all elements by . Function first calls function , then calls function .
The final function sequence first executes function , so all elements become .
Then when executing function , it first calls function , so all elements become . Then it calls function , so all elements become .
[Constraints]
::cute-table{tuack}
| Test Point ID | Other Special Constraints | ||
|---|---|---|---|
| The function call relations form a tree. | |||
| None. | |||
| No type functions, or no type functions. | |||
| None. | |||
| The function call relations form a tree. | |||
| None. | |||
| No type functions, or no type functions. | |||
| None. | |||
| The function call relations form a tree. | |||
| None. | |||
For all testdata: , , , , , 。
Translated by ChatGPT 5