#P3368. Range Update and Query on a Sequence
Range Update and Query on a Sequence
Range Update and Query on a Sequence
You are given a sequence of numbers. You need to perform the following two types of operations:
- Update: Add an integer \( x \) to every element in the interval [\( l \), \( r \)]. Formally, for every index \( i \) with \( l \leq i \leq r \), set \( a_i = a_i + x \).
- Query: Output the current value of the number at a given position.
All indices are 1-indexed.
inputFormat
The first line contains two integers \( n \) and \( q \) where \( n \) is the number of elements in the sequence and \( q \) is the number of operations. The second line contains \( n \) space-separated integers representing the initial sequence.
Each of the next \( q \) lines describes an operation in one of the following formats:
- For an update operation:
1 l r x
where you should add \( x \) to each element in the range \( [l, r] \). - For a query operation:
2 pos
where you should output the current value of the element at index \( pos \).
outputFormat
For each query operation (operation type 2), output the resulting value in a new line.
sample
5 5
1 2 3 4 5
2 3
1 1 3 10
2 1
2 5
1 2 5 -2
3
11
5
</p>