#C4503. Candy Bags Query Manager
Candy Bags Query Manager
Candy Bags Query Manager
You are given n empty candy bags numbered from 1 to n. Your task is to process q operations. There are two types of operations:
- Type 1:
1 i v
— Addv
candies to thei
-th bag. - Type 2:
2 i j
— Query the total number of candies in the bags from indexi
toj
(inclusive).
For a query operation, you need to output the sum of candies defined as
\[
S = \sum_{k=i}^{j} a_k
\]
where \(a_k\) is the number of candies in the k
-th bag.
Read from standard input and print the result for each query operation to standard output.
inputFormat
The first line contains two integers n
and q
— the number of candy bags and the number of operations.
The following q
lines each represent an operation. Each operation is given in one of the following two formats:
1 i v
— Addv
candies to bagi
.2 i j
— Output the sum of candies from bagi
to bagj
(inclusive).
Note: The bags are 1-indexed.
outputFormat
For each query operation (operation type 2), output the result on a new line. No output is required for addition operations.
## sample5 4
1 3 10
2 2 4
1 2 5
2 1 3
10
15
</p>