#P8360. [SNOI2022] 军队
[SNOI2022] 军队
Problem Description
Country R has a very long history.
There are cities in Country R, and there are political parties in the country, labeled . Since Country R is very long geographically, the positions of these cities can be approximated as points on a coordinate axis. At the very beginning of history, it is recorded that the -th city belongs to party , and there are troops stationed in the city.
In the history of Country R, the following three types of events often occur:
-
Party carried out a lobbying action, causing all cities from city to city that currently belong to party to change their affiliation to party .
-
Party carried out a recruitment action, increasing the number of troops by in all cities from city to city that currently belong to party .
-
A war broke out among all cities between city and city . 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 , representing the number of cities, the number of events, and the number of political parties in Country R.
The next line contains positive integers , representing the initial number of troops in each city.
The next line contains positive integers , representing the initial party affiliation of each city.
The next lines each contain to positive integers, describing an event:
The first integer indicates the type of the event. represent the lobbying, recruitment, and war events described in the Description.
For each lobbying event, the next integers are , with meanings as in the Description.
For each recruitment event, the next integers are , with meanings as in the Description.
For each war event, the next integers are , 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 , and their party affiliations are .
The events occur in the following order:
- Party attempts to recruit in cities . Cities and , which belong to party , each gain troops.
- A war breaks out among all cities between cities and , with scale .
- Party carries out a lobbying action in cities , causing cities and , which originally belong to party , to change their affiliation to party .
- Party attempts to recruit in cities . Cities and , which belong to party , each gain troops.
- A war breaks out among all cities between cities and , with scale .
- Party attempts to recruit in cities , but party currently owns no cities, so the recruitment does not succeed.
- A war breaks out among all cities between cities and , with scale .
Therefore, your program should output in order.
Constraints
For all testdata, , , .
The detailed constraints and special conditions are shown in the table below.
| Test Point ID | Special Conditions | ||
|---|---|---|---|
| For all operations, it is guaranteed that . | |||
| For all operations , it is guaranteed that . | |||
| It is guaranteed that there is no operation . | |||
Translated by ChatGPT 5