#P7346. 【DSOI 2021】归零

【DSOI 2021】归零

Background

A chance to talk with the Witch of Greed is something rare for other people.

For Q&A, only the two of us are needed. Let us skip the extra small talk; words alone are enough.

Your thirst for knowledge, curiosity, and greed—I acknowledge them all.

Speak, what do you want to ask?

Is it about the beast created against fate to save all living beings from hunger, the \left \lceil \right. Witch of Gluttony \left. \right \rfloor Daphne?

Is it about the one who wanted to fill the world with love and granted emotions to non-humans, the \left \lceil \right. Witch of Lust \left. \right \rfloor Camilla?

Is it about the one who lamented that the world is full of conflict, yet healed everyone with violence, the \left \lceil \right. Witch of Wrath \left. \right \rfloor Minerva?

Is it about the one who, just to seek peace, drove the dragon to the far side of the great waterfall, the \left \lceil \right. Witch of Sloth \left. \right \rfloor Sekhmet?

Is it about the one who relied on being young and innocent, yet punished the world without mercy, the \left \lceil \right. Witch of Pride \left. \right \rfloor Typhon?

Is it about the embodiment of the desire for knowledge, who sought all wisdom in the world and would not even give up the world after death, the \left \lceil \right. Witch of Greed \left. \right \rfloor Echidna?

Or is it about the \left \lceil \right. Witch of Envy \left. \right \rfloor, the taboo \left \lceil \right. “her” \left. \right \rfloor, who devoured all witches as her food and became an enemy of the world?

Problem Description

( If you feel the statement is unclear, please visit “Input Format” to see a simplified version.)

( Please read the guarantees to ensure you can solve the problem.)

What I want to ask is only...

Suppose I have a sequence aa of length nn, indexed from 1n1\rightarrow n, where aia_i denotes the ii-th number.

I will perform mm operations of four types, numbered in the given order:

\left \lceil \right. If I have two values xx and yy, I will use shadow magic to XOR yy onto all aia_i such that i0(modx)i \equiv 0 \pmod{x}. \left. \right \rfloor

\left \lceil \right. At the same time, I will reflect on myself and ask for the value of axa_x in the sequence. \left. \right \rfloor

\left \lceil \right. After many loops, I have learned that only by perfectly seizing every opportunity can I gain a greater advantage. Therefore I will compare axa_x with my expectation yy. If axya_x \le y, I will loop back and execute the shadow magic operations among operations numbered uvu \rightarrow v. \left. \right \rfloor

\left \lceil \right. Also, to prevent forgetting, I will loop back and execute operation number xx. \left. \right \rfloor

As you know, save points in looping cannot be interleaved, so my loops will not intersect.

Can you help me answer the questions in my mind?

Input Format

The first line contains two integers nn and mm, representing the length of the sequence and the number of operations.
The second line contains nn integers aia_i, representing the initial sequence.
Then follow mm lines, each containing some integers. Line i+2i + 2 describes operation number ii. The first integer opop is one of 141 \rightarrow 4:

  • op=1op = 1 : Read 3 integers 11, xx, yy. For all i0(modx)i \equiv 0 \pmod{x} (that is, xx, 2x2xkxkx, where kZ+k \in Z^+ and k×xnk \times x \le n), set ai=aiya_i = a_i \oplus y (\oplus denotes XOR).
  • op=2op = 2 : Read 2 integers 22, xx, and output axa_x.
  • op=3op = 3 : Read 5 integers 33, xx, yy, uu, vv. If axya_x \le y, execute all operations with op=1op = 1 among operations numbered uvu \rightarrow v; otherwise ignore this operation. It is guaranteed that uv<iu \le v < i.
  • op=4op = 4 : Read 2 integers 44, xx, and execute operation number xx. It is guaranteed that x<ix < i.

Because loops do not interleave, the problem guarantees:

  • If opi=3op_i = 3, then among operations numbered ui1u\rightarrow i-1, the type is definitely not 33 or 44.
  • Also, if opi=4op_i = 4, then among operations numbered x+1i1x+1\rightarrow i-1, the type is definitely not 33 or 44 (but operation xx itself may be of type 33 or 44, i.e., it can be called).

In mathematical language: if opi=3op_i = 3, then there are no 33 or 44 operations in [u,i)[u, i); if opi=4op_i = 4, then there are no 33 or 44 operations in (x,i)(x, i).

Output Format

Output several lines.
Each line is the answer to a query of type op=2op = 2, or the answer produced by a query operation that is invoked by a type op=4op = 4 call.

6 10
1 1 4 5 1 4
1 1 6
1 2 8
4 2
4 3
4 4
4 5 
4 6
2 1
2 3
2 4
7
2
3
6 10
2 3 7 1 9 0
1 1 2
3 4 10 1 1
1 3 3
4 3
2 5
2 6
1 2 8
4 5
4 8
2 6
9
0
9
9
8

Hint

[For sample 2, the values of the sequence during each operation are given below.]

Operation a1a_1 a2a_2 a3a_3 a4a_4 a5a_5 a6a_6 Explanation
None 2 3 7 1 9 0 Input
1st1_{st} 0 1 5 3 11 2 161\rightarrow6 all xorxor 22
2nd2_{nd} 2 3 7 1 9 0 a4=310a_4 = 3 \le 10, perform operation 11
3rd3_{rd} 4 3 33 // 66 both xorxor 3
4th4_{th} 7 0
5th5_{th} Output a5a_5
6th6_{th}
7th7_{th} 11 9 8 22 // 44 // 66 all xorxor 88
8th8_{th} Output a5a_5
9th9_{th}
10th10_{th} Output a6a_6

[Explanation of the “guarantees”]

For example, suppose the operation types are op1=1op_1 = 1, op2=4op_2 = 4, op3=2op_3 = 2, op4=3op_4 = 3, op5=1op_5 = 1, op6=4op_6=4. Then for op4op_4, the corresponding uu and vv can only be u=3u = 3, v=3v = 3, because u2u \le 2 would make its range contain an operation of type 44. For op6op_6, the corresponding xx can be 44 or 55, because then there are no type 33 or 44 operations between the right side of xx and the left side of operation 66.


[Constraints]
This problem uses bundled testdata. You must pass all test points in a subtask to obtain the score of that subtask. | Subtask | Special Property | Score | | :----------: | :----------: |:--------:| | 1 | Is sample 22 | 2 pts | | 2 | n10n \le 10, m10m \le 10 | 8 pts | | 3 | n1000n \le 1000, m1000m \le 1000 | 10 pts | | 4 | n104n \le 10^4, m104m \le 10^4 | 10 pts | | 5 | n105n \le 10^5, m5×105m \le 5 \times 10^5, no operation 44 | 10 pts | | 6 | n105n \le 10^5, m5×105m \le 5 \times 10^5, no operation 33 | 10 pts | | 7 | n105n \le 10^5, m5×105m \le 5 \times 10^5, random testdata | 18 pts | | 8 | n105n \le 10^5, m5×105m \le 5 \times 10^5 | 32 pts | For 100%100\% of the data, it is guaranteed that 1n1051 \le n \le 10^5, m5×105m \le 5 \times 10^5, and all values during the process and in the results are within the range of int.

Translated by ChatGPT 5