{"problem":{"name":"012 Inversion","description":{"content":"You are given a sequence $A=(A_1,\\ldots,A_N)$ of length $N$. Each element is $0$, $1$, or $2$.   Process $Q$ queries in order. Each query is of one of the following kinds: *   `1 L R`: print the inve","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":5000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc265_g"},"statements":[{"statement_type":"Markdown","content":"You are given a sequence $A=(A_1,\\ldots,A_N)$ of length $N$. Each element is $0$, $1$, or $2$.  \nProcess $Q$ queries in order. Each query is of one of the following kinds:\n\n*   `1 L R`: print the inversion number of the sequence $(A_L,\\ldots,A_R)$.\n*   `2 L R S T U`: for each $i$ such that $L\\leq i \\leq R$, if $A_i$ is $0$, replace it with $S$; if $A_i$ is $1$, replace it with $T$; if $A_i$ is $2$, replace it with $U$.\n\nWhat 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$.\n\n## Constraints\n\n*   $1 \\leq N \\leq 10^5$\n*   $0 \\leq A_i \\leq 2$\n*   $1\\leq Q\\leq 10^5$\n*   In each query, $1\\leq L \\leq R \\leq N$.\n*   In each query of the second kind, $0\\leq S,T,U \\leq 2$.\n*   All values in input are integers.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $Q$\n$A_1$ $A_2$ $\\ldots$ $A_N$\n$\\rm Query_1$\n$\\rm Query_2$\n$\\vdots$\n$\\rm Query_Q$\n\n$\\rm Query_i$ denotes the $i$\\-th query, which is in one of the following formats:\n\n$1$ $L$ $R$\n\n$2$ $L$ $R$ $S$ $T$ $U$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc265_g","tags":[],"sample_group":[["5 3\n2 0 2 1 0\n1 2 5\n2 2 4 2 1 0\n1 2 5","3\n4\n\nInitially, $A=(2,0,2,1,0)$.\n\n*   In the $1$\\-st query, print the inversion number $3$ of $(A_2,A_3,A_4,A_5)=(0,2,1,0)$.\n*   The $2$\\-nd query makes $A=(2,2,0,1,0)$.\n*   In the $3$\\-rd query, print the inversion number $4$ of $(A_2,A_3,A_4,A_5)=(2,0,1,0)$."],["3 3\n0 1 2\n1 1 1\n2 1 3 0 0 0\n1 1 3","0\n0"]],"created_at":"2026-03-03 11:01:14"}}