#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:
- Add a specific value to a designated element in the data;
- Multiply every element in the data by the same value;
- 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 , representing the number of data elements.
The second line contains integers, where the -th integer denotes the initial value of the data element with index as .
The third line contains a positive integer , representing the number of functions provided by the database application. The functions are numbered from to .
For the next lines, the first integer in the -th line () is , indicating the type of the -th function:
- If , the next two integers and respectively represent the index of the element to which the addition is performed and the value to be added;
- If , the next integer represents the value by which all elements are multiplied;
- If , the next positive integer represents the number of functions to be called by the -th function, followed by integers which denote the numbers of the functions to be called in sequence.
The -th line contains a positive integer , representing the length of the input function operation sequence.
The -th line contains integers , where the -th integer denotes the number of the function to be executed as the -th step.
Output Format
Output a line of integers separated by spaces, in the order of indices to , representing the value of each element in the database after executing the input function sequence. The answer should be taken modulo .
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 . 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 .
When executing Function 3 next, it first calls Function 1, changing the values of all elements to . Then it calls Function 2, changing the values of all elements to .
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 | Other Special Restrictions | ||
|---|---|---|---|
| The function call relationship forms a tree | |||
| None | |||
| No Type 2 functions or no Type 1 functions | |||
| None | |||
| The function call relationship forms a tree | |||
| None | |||
| No Type 2 functions or no Type 1 functions | |||
| None | |||
| The function call relationship forms a tree | |||
| None | |||
For all test cases: , , , , , .