#C10757. Robot Battery Level Simulator
Robot Battery Level Simulator
Robot Battery Level Simulator
The problem involves simulating operations on a list of robots' battery levels. Initially, each robot has a battery level given in the input. Two types of operations can be performed:
- Add Operation: Given indices \(l\) and \(r\) (1-indexed) and an integer \(x\), add \(x\) to the battery level of every robot in the range \([l, r]\).
- Query Operation: Given an index \(i\) (1-indexed), output the battery level of the \(i\)-th robot.
Only query operations produce an output. Handle the operations in the same order as they appear in the input. Your solution must read from standard input and write to standard output.
inputFormat
The first line contains two integers (n) and (q) where (n) is the number of robots and (q) is the number of operations. The second line contains (n) integers representing the initial battery levels of the robots. This is followed by (q) lines, each describing an operation in one of the following formats:
1 l r x
: Add \(x\) to each battery level from index \(l\) to \(r\) (both inclusive, 1-indexed).2 i
: Query and output the battery level of the robot at index \(i\) (1-indexed).
outputFormat
For each query operation (of type 2), output the corresponding battery level on a separate line.## sample
5 5
10 20 30 40 50
1 2 4 10
2 3
1 1 5 5
2 5
2 1
40
55
15
</p>