#P7453. Magic Crystal Balls
Magic Crystal Balls
Magic Crystal Balls
Little magician L created n magic crystal balls. Each ball has three kinds of energy corresponding to the water, fire, and earth elements with initial values \(A_i\), \(B_i\), and \(C_i\) (for \(1 \le i \le n\)), respectively. The crystal balls are arranged in a line from front to back, and then magician L performs m magical operations on them.
There are three categories of magic, containing a total of 7 operations:
- Magic Activation: In this category, for a chosen interval \([l, r]\), one specific elemental energy triggers another energy's explosion (the triggering does not change the triggering energy). The three possible operations are:
- Fire activates water: \(A_i = A_i + B_i \; (\bmod\ 998244353)\).
- Earth activates fire: \(B_i = B_i + C_i \; (\bmod\ 998244353)\).
- Water activates earth: \(C_i = C_i + A_i \; (\bmod\ 998244353)\).
- Magic Enhancement: Magician L consumes \(v\) units of his own magic power to change a specific attribute of each ball in the interval \([l, r]\). The three possible enhancements are:
- Fixed increase of fire energy: \(A_i = A_i + v \; (\bmod\ 998244353)\).
- Multiplicative enhancement of water energy: \(B_i = B_i \times v \; (\bmod\ 998244353)\).
- Setting earth energy: \(C_i = v \; (\bmod\ 998244353)\).
- Magic Release: Magician L aggregates the energies of all crystal balls in the interval \([l, r]\) and fuses them into a new crystal ball. The resulting ball's energy in each attribute is the sum of the corresponding energies of the balls in the interval, modulo \(998244353\). The original balls remain unchanged.
Note: All energy values are taken modulo \(998244353\) to prevent any explosion.
For the operations, each is represented by a code number between 1 and 7 as follows:
- 1: Fire activates water (update \(A_i = A_i + B_i\)).
- 2: Earth activates fire (update \(B_i = B_i + C_i\)).
- 3: Water activates earth (update \(C_i = C_i + A_i\)).
- 4: Fixed increase on fire energy (update \(A_i = A_i + v\)).
- 5: Multiplicative enhancement on water energy (update \(B_i = B_i \times v\)).
- 6: Set earth energy (update \(C_i = v\)).
- 7: Magic release (query): compute the sums of \(A_i\), \(B_i\), and \(C_i\) over the interval \([l, r]\) modulo \(998244353\).
The input begins with two integers \(n\) and \(m\). The next three lines each contain \(n\) space-separated integers representing the initial energy values of \(A\), \(B\), and \(C\) respectively. Then follow m operations. For operations of types 1, 2, 3, and 7, the line contains three integers: the operation code, l and r. For operations of types 4, 5, and 6, an additional integer \(v\) is provided.
After processing all operations, for every Magic Release (operation code 7), output the energy values of the resulting fused crystal ball.
inputFormat
The input is given as follows:
n m A1 A2 ... An B1 B2 ... Bn C1 C2 ... Cn operation1 operation2 ... operationm
Each operation is formatted as follows:
- If the operation code is 1, 2, 3, or 7:
code l r
- If the operation code is 4, 5, or 6:
code l r v
All arithmetic operations are performed modulo \(998244353\).
outputFormat
For each Magic Release operation (operation code 7), output a single line containing three space-separated integers: the sums of \(A_i\), \(B_i\), and \(C_i\) over the given interval, modulo \(998244353\).
sample
3 5
1 2 3
4 5 6
7 8 9
1 1 3
4 2 3 10
7 1 2
6 1 1 100
7 1 3
22 9 15
41 15 117
</p>