This can be done very easily using brute force, but if the array-size is huge, then performing the operations on a sub-array iteratively can be expensive. For that, need to basically only measure the delta between additions.
The explanation is detailed properly in the answer given below. Answer link - https://www.geeksforgeeks.org/constant-time-range-add-operation-array/