#P3278. [SCOI2013] 多项式的运算
[SCOI2013] 多项式的运算
Description
One day, while thinking about a project, mzry1992 was riding a motorcycle on the highway. A bald guy kicked him, his motorcycle broke down, and he was sent to the school hospital for an IV drip. With the deadline approaching, he has to ask you to help finish the project.
The goal of this project is to maintain a dynamic infinite polynomial in . Initially, for all , we have .
.
There are four types of operations:
- Multiply the coefficients of the terms from to by a fixed value .
- Add a fixed value to the coefficients of the terms from to .
- Multiply the terms from to by the variable .
- Substitute a fixed value into and output the resulting value. After the query, the polynomial is restored to its previous state.
After observation, the team found that users mainly use the first three operations, and the fourth operation appears no more than times. mzry1992 is responsible for the core code of this project. Can you help him implement it?
Input Format
The first line contains an integer , representing the number of operations.
Then follow lines, each containing one operation in one of the following formats:
- mul L R v: the first type of operation.
- add L R v: the second type of operation.
- mulx L R: the third type of operation.
- query v: the fourth type of operation.
Output Format
For each query operation, output the corresponding answer. Since the result may be large, print it modulo .
6
add 0 1 7
query 1
mul 0 1 7
query 2
mulx 0 1
query 3
14
147
588
Hint
[Sample Explanation]
After operation 1, the polynomial is .
After operation 3, the polynomial is .
After operation 5, the polynomial is .
Constraints
- For of the testdata: , , .
- For another of the testdata: , , , and there is no mulx operation.
- For the remaining of the testdata: , , .
Translated by ChatGPT 5
京公网安备 11011102002149号