#abc265g. [abc265_g]012 Inversion

[abc265_g]012 Inversion

Problem Statement

You are given a sequence A=(A1,ldots,AN)A=(A_1,\\ldots,A_N) of length NN. Each element is 00, 11, or 22.
Process QQ queries in order. Each query is of one of the following kinds:

  • 1 L R: print the inversion number of the sequence (AL,ldots,AR)(A_L,\\ldots,A_R).
  • 2 L R S T U: for each ii such that LleqileqRL\\leq i \\leq R, if AiA_i is 00, replace it with SS; if AiA_i is 11, replace it with TT; if AiA_i is 22, replace it with UU.

What is the inversion number? The inversion number of a sequence B=(B1,ldots,BM)B = (B_1, \\ldots, B_M) is the number of pairs of integers (i,j)(i, j) (1leqi<jleqM)(1 \\leq i < j \\leq M) such that Bi>BjB_i > B_j.

Constraints

  • 1leqNleq1051 \\leq N \\leq 10^5
  • 0leqAileq20 \\leq A_i \\leq 2
  • 1leqQleq1051\\leq Q\\leq 10^5
  • In each query, 1leqLleqRleqN1\\leq L \\leq R \\leq N.
  • In each query of the second kind, 0leqS,T,Uleq20\\leq S,T,U \\leq 2.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN QQ A1A_1 A2A_2 ldots\\ldots ANA_N rmQuery1\\rm Query_1 rmQuery2\\rm Query_2 vdots\\vdots rmQueryQ\\rm Query_Q

rmQueryi\\rm Query_i denotes the ii-th query, which is in one of the following formats:

11 LL RR 22 LL RR SS TT UU

Output

Print the responses to the queries of the first kind in the given order, separated by newlines.


Sample Input 1

5 3
2 0 2 1 0
1 2 5
2 2 4 2 1 0
1 2 5

Sample Output 1

3
4

Initially, A=(2,0,2,1,0)A=(2,0,2,1,0).

  • In the 11-st query, print the inversion number 33 of (A2,A3,A4,A5)=(0,2,1,0)(A_2,A_3,A_4,A_5)=(0,2,1,0).
  • The 22-nd query makes A=(2,2,0,1,0)A=(2,2,0,1,0).
  • In the 33-rd query, print the inversion number 44 of (A2,A3,A4,A5)=(2,0,1,0)(A_2,A_3,A_4,A_5)=(2,0,1,0).

Sample Input 2

3 3
0 1 2
1 1 1
2 1 3 0 0 0
1 1 3

Sample Output 2

0
0