#K72327. Game Array Operations Challenge
Game Array Operations Challenge
Game Array Operations Challenge
In this problem, you are given an array of (n) integers, initially set to zero. You are required to process (q) operations on the array. There are three types of operations:
-
Increment Operation: "1 l r v" - Increase each element in the subarray from index (l) to (r) (inclusive) by (v). This means for every index (i) such that (l \leq i \leq r), update (a_i = a_i + v).
-
Reset Operation: "2 x" - Reset the element at index (x) to zero.
-
Sum Query Operation: "3 l r" - Calculate and output the sum of elements from index (l) to (r) (inclusive).
Note that the indices provided are 1-indexed. The operations are given in order and must be executed sequentially. For each sum query, output the result on a new line.
inputFormat
The first line contains two integers (n) and (q) where (n) represents the size of the array and (q) is the number of operations. Each of the following (q) lines contains an operation in one of the following formats:
- For an increment operation:
1 l r v
- For a reset operation:
2 x
- For a sum query operation:
3 l r
All values are separated by spaces.
outputFormat
For each sum query operation (i.e., operations that start with a 3), output the resulting sum on a new line.## sample
5 5
1 1 3 2
3 1 3
2 2
3 1 3
1 2 5 3
6
4
</p>