#P7453. [THUSC 2017] 大魔法师

[THUSC 2017] 大魔法师

Problem Description

Great Wizard Little L made nn magic crystal balls. Each crystal ball has three attribute energy values: water, fire, and earth. Little L lined up these nn crystal balls on the ground from front to back, and then started today’s magic show.

We use Ai,Bi,CiA_i,B_i,C_i to represent the water, fire, and earth energy values of the ii-th crystal ball from front to back (indices start from 11).

Little L plans to cast mm spells. Each time, he chooses an interval [l,r][l,r], and then casts one of the following 33 categories and 77 types of spells:

  1. 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 Ai=Ai+BiA_i=A_i+B_i.
    • Earth activates fire energy: set Bi=Bi+CiB_i=B_i+C_i.
    • Water activates earth energy: set Ci=Ci+AiC_i=C_i+A_i.

    Note that enhancing one attribute’s energy will not change the other attribute’s energy. For example, Ai=Ai+BiA_i=A_i+B_i will not increase or decrease BiB_i.

  2. Magic Enhancement: Little L swings his staff and spends vv 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 Ai=Ai+vA_i=A_i+v.
    • Fire energy multiply increase: set Bi=Bi×vB_i=B_i\times v.
    • Earth energy absorption and fusion: set Ci=vC_i=v.
  3. 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 998244353998244353. 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 77 types of spells from top to bottom as 171\sim7.

The first line contains an integer nn (1n2.5×1051\le n\le 2.5\times 10^5), the number of crystal balls.

The next nn lines each contain 33 integers separated by spaces. The three numbers on the ii-th line are Ai,Bi,CiA_i,B_i,C_i in order.

The next line contains an integer mm (1m2.5×1051\le m\le2.5\times 10^5), the number of spells cast.

The next mm lines each contain 33 or 44 numbers in the format opt l r (v). Here opt is the spell number, and l,rl,r define the interval (it is guaranteed that lrl\le r). In particular, if spell 464\sim6 (Magic Enhancement) is cast, there is an additional integer vv, which is the mana spent by Little L.

Output Format

Write to standard output.

For each spell 77 (Magic Release), output one line with 33 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 100%100\% of the testdata, $1\le n,m\le2.5\times 10^5,0\le A_i,B_i,C_i,v<998244353$.

  1. For 10%10\% of the testdata, n×m107n\times m\le10^7.
  2. Another 10%10\% of the testdata: the interval of every spell is [1,n][1,n].
  3. Another 10%10\% of the testdata: for every non-query spell, its affected interval is [1,n][1,n], and all modifications happen before the queries.
  4. Another 10%10\% of the testdata: opt{4,5,6,7}\operatorname{opt}\in\{4,5,6,7\}.
  5. Another 15%15\% of the testdata: opt{1,2,7}\operatorname{opt}\in\{1,2,7\}.
  6. Another 15%15\% of the testdata: opt{1,2,3,5,7}\operatorname{opt}\in\{1,2,3,5,7\}.
  7. Another 15%15\% of the testdata: n,m105n,m\le 10^5.
  8. 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