#4622. 012 Inversion

0

012 Inversion

012 Inversion

题目描述

You are given a sequence A=(A1,…,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:

1LR1 L R: print the inversion number of the sequence (AL,…,AR)(A_L,\ldots,A_R). 2LRSTU2 L R S T U: for each ii such that L≤i≤RL\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 = (B_1, \ldots, B_M)$ is the number of pairs of integers $(i, j)$ $(1 \leq i < j \leq M)$ such that $B_i > B_j$.

输入格式

Input is given from Standard Input in the following format: NN QQ A1A_1 A2A_2 …\ldots ANA_N Query1\rm Query_1 Query2\rm Query_2 ⋮\vdots QueryQ\rm Query_Q

Queryi\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

输出格式

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

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

提示

1≤N≤1051 \leq N \leq 10^5 0≤Ai≤20 \leq A_i \leq 2 1≤Q≤1051\leq Q\leq 10^5 In each query, 1≤L≤R≤N1\leq L \leq R \leq N. In each query of the second kind, 0≤S,T,U≤20\leq S,T,U \leq 2. All values in input are integers.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).

标签: AtCoder|abc265G

来源

AtCoder|abc265G