#C9129. Aquarium Operations
Aquarium Operations
Aquarium Operations
In this problem, you are given an initial list of fish weights and a series of operations to perform on them. Each operation is either a feeding operation, where the weight of a specific fish is increased, or a query operation, which asks for the sum of weights within a given range. Specifically, a feeding operation is denoted by (F) and increases the weight of the fish with a given ID, while a query operation is denoted by (Q) and outputs the sum of weights for fish with IDs in a specified interval. Your task is to process all operations in the order they are given and output the result for each query.
For example, given 5 fish with initial weights [10, 20, 30, 40, 50] and operations: Q 1 3, F 2 10, Q 2 4, F 3 5, Q 1 5
, the output should be 60, 100, 165
corresponding to the queries.
inputFormat
The first line of input contains two integers (n) and (q), where (n) is the number of fish species and (q) is the number of operations. The second line contains (n) integers, representing the initial weights of the fish from species with ID 1 to (n). Each of the following (q) lines describes an operation in one of the following formats:
• (F~s~x): Feed the fish with species ID (s) by adding (x) to its weight.
• (Q~l~r): Query the sum of weights of fish with IDs between (l) and (r) (inclusive).
outputFormat
For each query operation, output a single integer representing the sum of the weights of the fish in the specified range. Each result should be printed on a new line to standard output.## sample
5 5
10 20 30 40 50
Q 1 3
F 2 10
Q 2 4
F 3 5
Q 1 5
60
100
165
</p>