#P8360. [SNOI2022] 军队

[SNOI2022] 军队

Problem Description

Country R has a very long history.

There are nn cities in Country R, and there are CC political parties in the country, labeled 1,2,,C1,2,\dots,C. Since Country R is very long geographically, the positions of these nn cities can be approximated as nn points on a coordinate axis. At the very beginning of history, it is recorded that the ii-th city belongs to party cic_i, and there are aia_i troops stationed in the city.

In the history of Country R, the following three types of events often occur:

  1. Party yy carried out a lobbying action, causing all cities from city ll to city rr that currently belong to party xx to change their affiliation to party yy.

  2. Party xx carried out a recruitment action, increasing the number of troops by vv in all cities from city ll to city rr that currently belong to party xx.

  3. A war broke out among all cities between city ll and city rr. The scale of the war can be described as the sum of the numbers of troops in all cities in that range. Note that wars do not necessarily happen between different parties; civil wars may also occur within cities belonging to the same party. Since Country R’s medical system is advanced enough, wars do not reduce the number of troops.

Little N is a girl who likes history. Recently, she wants to organize the war history of Country R, especially the scale of each war. However, since the history of Country R is far too long, it is too hard for her to compute everything with pen and paper. So she came to you, hoping you can write a program to compute the scales of all wars in Country R’s history.

Input Format

The first line contains three positive integers n,q,Cn,q,C, representing the number of cities, the number of events, and the number of political parties in Country R.

The next line contains nn positive integers a1,a2,,ana_1,a_2,\dots,a_n, representing the initial number of troops in each city.

The next line contains nn positive integers c1,c2,,cnc_1,c_2,\dots,c_n, representing the initial party affiliation of each city.

The next qq lines each contain 33 to 55 positive integers, describing an event:

The first integer op\mathit{op} indicates the type of the event. op=1,2,3\mathit{op}=1,2,3 represent the lobbying, recruitment, and war events described in the Description.

For each lobbying event, the next 44 integers are l,r,x,yl,r,x,y, with meanings as in the Description.

For each recruitment event, the next 44 integers are l,r,x,vl,r,x,v, with meanings as in the Description.

For each war event, the next 22 integers are l,rl,r, with meanings as in the Description.

Output Format

For each war event, output one integer per line, indicating the scale of this war.

5 7 3
1 2 4 8 16
1 2 3 2 3
2 2 4 2 32
3 1 4
1 1 5 3 1
2 2 5 1 64
3 2 4
2 1 3 3 128
3 3 5

79
142
188

样例 2 见附件 military2.in
本组数据满足测试点 4 的限制。
样例 2 见附件 military2.ans
样例 3 见附件 military3.in
本组数据满足测试点 14 的限制。
样例 3 见附件 military3.ans
样例 4 见附件 military4.in
本组数据满足测试点 18 的限制。
样例 4 见附件 military4.ans

Hint

Sample 1 Explanation

Initially, the numbers of troops in the five cities are 1,2,4,8,161, 2, 4, 8, 16, and their party affiliations are 1,2,3,2,31, 2, 3, 2, 3.

The events occur in the following order:

  • Party 22 attempts to recruit in cities 2,3,42, 3, 4. Cities 22 and 44, which belong to party 22, each gain 3232 troops.
  • A war breaks out among all cities between cities 11 and 44, with scale 1+34+4+40=791 + 34 + 4 + 40 = 79.
  • Party 11 carries out a lobbying action in cities 1,2,3,4,51, 2, 3, 4, 5, causing cities 33 and 55, which originally belong to party 33, to change their affiliation to party 11.
  • Party 11 attempts to recruit in cities 2,3,4,52, 3, 4, 5. Cities 33 and 55, which belong to party 11, each gain 6464 troops.
  • A war breaks out among all cities between cities 22 and 44, with scale 34+68+40=14234 + 68 + 40 = 142.
  • Party 33 attempts to recruit in cities 1,2,31, 2, 3, but party 33 currently owns no cities, so the recruitment does not succeed.
  • A war breaks out among all cities between cities 33 and 55, with scale 68+40+80=18868 + 40 + 80 = 188.

Therefore, your program should output 79,142,18879, 142, 188 in order.

Constraints

For all testdata, 1n,q2.5×1051 \leq n, q\leq 2.5 \times 10^5, 1ai,v1081 \leq a_i, v \leq 10^8, 1ci,x,yC1 \leq c_i, x, y \leq C.

The detailed constraints and special conditions are shown in the table below.

Test Point ID n,qn,q\leq CC\leq Special Conditions
11 2020
22 5050
33 300300
44 50005000
55 10510^5 1010
66 1.5×1051.5 \times 10^5
77 2×1052 \times 10^5
88 2.5×1052.5 \times 10^5
99 1.5×1051.5 \times 10^5 For all operations, it is guaranteed that l=1,r=nl=1,r=n.
1010 2.5×1052.5 \times 10^5
1111 1.5×1051.5 \times 10^5 For all operations 1,21,2, it is guaranteed that l=1,r=nl=1,r=n.
1212 2×1052 \times 10^5
1313 2.5×1052.5 \times 10^5 2.5×1052.5 \times 10^5
1414 1.5×1051.5 \times 10^5 It is guaranteed that there is no operation 11.
1515 2.5×1052.5 \times 10^5
1616 10510^5
1717 1.5×1051.5 \times 10^5
1818 2×1052 \times 10^5 2×1052\times 10^5
1919 2.5×1052.5 \times 10^5
2020

Translated by ChatGPT 5