#C10714. Zoo Operations
Zoo Operations
Zoo Operations
In this problem, you are given a zoo with n cages, each containing a certain number of animals. You will be asked to perform q operations on these cages. There are two types of operations:
- count l r: Compute the sum of animals in cages numbered from l to r (inclusive). Formally, compute (\sum_{i=l}^{r} a_i), where (a_i) represents the number of animals in the (i)-th cage.
- move u v: Transfer all animals from cage u to cage v. After the transfer, the number of animals in cage u becomes zero, and cage v increases by that amount.
Make sure to process the operations sequentially as they are given. The result of each "count" operation should be printed in the order they appear, each on a new line.
inputFormat
The first line contains an integer n, the number of cages.
The second line contains n space-separated integers, where the i-th integer represents the number of animals in the i-th cage ((a_i)).
The third line contains an integer q, the number of operations.
Each of the next q lines describes an operation in one of the following formats:
- For a count operation:
count l r
- For a move operation:
move u v
Here, l, r, u, and v are 1-indexed.
outputFormat
For each count operation, output a single line containing the sum of animals in the specified range.## sample
5
3 2 5 7 9
4
count 1 3
move 2 4
count 1 3
count 3 5
10
8
23
</p>