#P7453. [THUSC 2017] 大魔法师
[THUSC 2017] 大魔法师
Problem Description
Great Wizard Little L made magic crystal balls. Each crystal ball has three attribute energy values: water, fire, and earth. Little L lined up these crystal balls on the ground from front to back, and then started today’s magic show.
We use to represent the water, fire, and earth energy values of the -th crystal ball from front to back (indices start from ).
Little L plans to cast spells. Each time, he chooses an interval , and then casts one of the following categories and types of spells:
-
Magic Activation: make the energy of a specific attribute burst, thereby enhancing the energy of another specific attribute for every crystal ball in the interval. Specifically, there are three possible forms:
- Fire activates water energy: set .
- Earth activates fire energy: set .
- Water activates earth energy: set .
Note that enhancing one attribute’s energy will not change the other attribute’s energy. For example, will not increase or decrease .
-
Magic Enhancement: Little L swings his staff and spends mana points to change the energy of a specific attribute for every crystal ball in the interval. Specifically, there are three possible forms:
- Water energy fixed increase: set .
- Fire energy multiply increase: set .
- Earth energy absorption and fusion: set .
-
Magic Release: Little L gathers the energy of all crystal balls in the interval, fuses them into a new crystal ball, and then gives it to the audience outside the field. In the generated crystal ball, each attribute’s energy value equals the algebraic sum of the corresponding energy values of all crystal balls in the interval. Note that the process of magic release does not actually change the energy of the crystal balls in the interval.
It is worth mentioning that the raw materials of the crystal balls made and fused by Little L are custom OI-factory crystals, so these crystal balls have an energy threshold . When the energy value of some attribute in a crystal ball is greater than or equal to this threshold, the value will automatically be taken modulo the threshold, to avoid the crystal ball exploding.
Little W, Little L’s (only) audience, watched the entire show and received each crystal ball fused by Little L during the performance. Little W wants to know the energy values of the three attributes contained in these crystal balls.
Input Format
Read input from standard input.
We label the above types of spells from top to bottom as .
The first line contains an integer (), the number of crystal balls.
The next lines each contain integers separated by spaces. The three numbers on the -th line are in order.
The next line contains an integer (), the number of spells cast.
The next lines each contain or numbers in the format opt l r (v). Here opt is the spell number, and define the interval (it is guaranteed that ). In particular, if spell (Magic Enhancement) is cast, there is an additional integer , which is the mana spent by Little L.
Output Format
Write to standard output.
For each spell (Magic Release), output one line with integers separated by spaces, a b c, representing the water, fire, and earth energy values of the fused crystal ball.
2
2 3 3
6 6 6
4
7 1 2
1 1 2
4 1 2 3
7 1 2
8 9 9
23 9 9
Hint
For of the testdata, $1\le n,m\le2.5\times 10^5,0\le A_i,B_i,C_i,v<998244353$.
- For of the testdata, .
- Another of the testdata: the interval of every spell is .
- Another of the testdata: for every non-query spell, its affected interval is , and all modifications happen before the queries.
- Another of the testdata: .
- Another of the testdata: .
- Another of the testdata: .
- Another of the testdata: .
- Other testdata: no special constraints.
Sample Explanation
The following shows the energy in the two crystal balls after each spell is cast:
(2, 3, 3) (6, 6, 6)
(5, 3, 3) (12, 6, 6)
(8, 3, 3) (15, 6, 6)
(8, 3, 3) (15, 6, 6)
Translated by ChatGPT 5