#abc265g. G - 012 Inversion

G - 012 Inversion

Score : 600600 points

问题描述

给定一个长度为 NN 的序列 A=(A1,,AN)A=(A_1,\ldots,A_N),其中每个元素为 001122

按顺序处理 QQ 个查询。每个查询属于以下两种类型之一:

  • 1 L R:打印子序列 (AL,,AR)(A_L,\ldots,A_R) 的逆序数。
  • 2 L R S T U:对于满足 LiRL\leq i \leq R 的所有 ii,若 AiA_i00,则将其替换为 SS;若 AiA_i11,则替换为 TT;若 AiA_i22,则替换为 UU

什么是逆序数?一个序列 B=(B1,,BM)B = (B_1, \ldots, B_M) 的逆序数是指满足条件 (i,j)(i, j) (1i<jM)(1 \leq i < j \leq M)Bi>BjB_i > B_j 的整数对的数量。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

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:

  • 1 L R: print the inversion number of the sequence (AL,,AR)(A_L,\ldots,A_R).
  • 2 L R S T U: for each ii such that LiRL\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,,BM)B = (B_1, \ldots, B_M) is the number of pairs of integers (i,j)(i, j) (1i<jM)(1 \leq i < j \leq M) such that Bi>BjB_i > B_j.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 0Ai20 \leq A_i \leq 2
  • 1Q1051\leq Q\leq 10^5
  • In each query, 1LRN1\leq L \leq R \leq N.
  • In each query of the second kind, 0S,T,U20\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 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

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

update @ 2024/3/10 11:13:18