#P7709. 「Wdsr-2.7」八云蓝自动机 Ⅱ

「Wdsr-2.7」八云蓝自动机 Ⅱ

Description

The Yakumo Ran Automaton maintains a sequence AA of length nn, where each element has an initial value. The automaton supports the following three operations:

  • 1 l r k\colorbox{f0f0f0}{\verb!1 l r k!}: Set all numbers in the range [l,r][l,r] to kk, i.e., Alk,Al+1k,,ArkA_l\gets k,A_{l+1}\gets k,\cdots ,A_r\gets k.

  • 2 x y\colorbox{f0f0f0}{\verb!2 x y!}: Swap the values of AxA_x and AyA_y.

  • 3 x\colorbox{f0f0f0}{\verb!3 x!}: Query the value of AxA_x.

To test the efficiency of the Yakumo Ran Automaton, Yukari needs to run a huge number of tests. To generate all operations for each test, Yukari constructed an operation sequence BB of length mm, where each element of BB is an operation that the Yakumo Ran Automaton can execute.

Let Υ(l,r)\Upsilon(l,r) denote the sum of the results of all type 33 operations after starting from the initial state and executing operations Bl,Bl+1,BrB_l,B_{l+1},\cdots B_r in order. In particular, if there is no type 33 operation among them, then Υ(l,r)=0\Upsilon(l,r)=0.

Yukari will ask the Yakumo Ran Automaton qq queries. Each query gives a triple (l,r,p)(l,r,p), and the automaton needs to compute

$$\left(\sum_{i=l}^r \Upsilon(i,p)\right) \mod 2^{32}$$

Input Format

  • The first line contains two integers n,mn,m, with meanings as described above.

  • The second line contains nn integers, the initial values of sequence AA.

  • The next mm lines describe the operation sequence BB. For each operation, the first integer is opop, indicating the operation type.

    • If op=1op = 1, then three integers l,r,kl,r,k follow, describing a type 11 operation.

    • If op=2op = 2, then two integers x,yx,y follow, describing a type 22 operation.

    • If op=3op = 3, then one integer xx follows, describing a type 33 operation.

  • The next line contains an integer qq, the total number of queries initiated by Yakumo Yukari.

  • The next qq lines each contain three integers l,r,pl,r,p, describing a query, with the execution as stated above.

Output Format

  • Output qq lines. Each line contains one integer, the answer to the corresponding query.
10 10
12 11 6 6 1 18 9 1 13 20 
2 1 8
1 7 7 12
2 4 10
2 5 10
2 9 5
3 7
1 4 8 7
1 1 9 13
3 5
3 6
10
1 4 10
3 3 3
2 2 7
1 4 6
2 2 9
1 8 8
2 6 8
2 6 8
2 5 6
1 4 9

146
0
12
42
25
60
48
48
39
94

Hint

  • This problem has one and only one Subtask\textbf{Subtask}. In this Subtask\text{Subtask}, the first few testdata satisfy n,m,q5×103n,m,q \le 5 \times 10^3, which can be used to check the correctness of your algorithm.

  • For 100%100\% of the testdata, it holds that:

    • 1n,m,q3×1051 \le n,m,q \le 3 \times 10 ^ 5.

    • $1 \le a_i,k \le 10^9;1 \le op \le 3;1 \le x,y \le n;x \neq y$.

    • For all operations, 1lrn1 \le l \le r \le n; for all queries, 1lrpm1 \le l \le r \le p \le m.

Translated by ChatGPT 5