#P8360. War Scale Calculation in R Nation History
War Scale Calculation in R Nation History
War Scale Calculation in R Nation History
The nation of R has a long history. It has \(n\) cities arranged along a line and \(C\) political parties numbered from 1 to \(C\). Initially, the \(i\)-th city is under party \(c_i\) and has an army of size \(a_i\).
There are three types of events in R's history:
- Persuasion: Party \(y\) convinces all cities from index \(l\) to \(r\) to change their affiliation to \(y\). Formally, for every city \(i\) with \(l \le i \le r\), the party is set to \(y\).
- Conscription: Party \(x\) carries out conscription in cities from \(l\) to \(r\). For every city \(i\) in this range that is currently under party \(x\), its army size increases by \(v\). That is, if \(c_i = x\), then \(a_i \mathrel{+}= v\).
- War: A war breaks out among all cities from index \(l\) to \(r\). The scale of the war is defined as the sum of the army sizes of all cities within that range. Note that wars, even if they occur within the same party, do not reduce army sizes.
You are given the initial information along with a sequence of \(q\) events. For each war event, you need to compute and output the war's scale.
Input/Output Details are provided below.
inputFormat
The first line contains three integers \(n\), \(C\), and \(q\) representing the number of cities, the number of parties, and the number of events respectively.
The second line contains \(n\) integers \(c_1, c_2, \ldots, c_n\), where \(c_i\) is the initial party affiliation of the \(i\)-th city.
The third line contains \(n\) integers \(a_1, a_2, \ldots, a_n\), where \(a_i\) is the initial army count in the \(i\)-th city.
The following \(q\) lines each describe an event. Each event is in one of the following formats:
- For a Persuasion event:
1 l r y
- For a Conscription event:
2 l r x v
- For a War event:
3 l r
Indices are 1-based. For each War event, you need to output the sum of the army counts from the \(l\)-th to the \(r\)-th city.
outputFormat
For each War event in the input, output a single line containing one integer, denoting the scale of that war.
sample
5 3 5
1 2 3 1 2
10 20 30 40 50
3 1 5
1 2 4 3
2 1 3 1 10
3 2 5
3 1 3
150
140
70
</p>