Print modified array after multiple array range increment operations | function to increment values in the given range by a value d for multiple queries ; for each ( start , end ) index pair perform the following operations on 'sum[]   ; increment the value at index ' start ' by the given value ' d ' in 'sum[]   ; if the index ' ( end + 1 ) ' exists then decrement the value at index ' ( end + 1 ) ' by the given value ' d ' in 'sum[]   ; Now , perform the following operations : accumulate values in the ' sum [ ] ' array and then add them to the corresponding indexes in 'arr[]   ; function to print the elements of the given array ; Driver Code ; modifying the array for multiple queries
def incrementByD ( arr , q_arr , n , m , d ) : NEW_LINE INDENT sum = [ 0 for i in range ( n ) ] NEW_LINE for i in range ( m ) : NEW_LINE INDENT sum [ q_arr [ i ] [ 0 ] ] += d NEW_LINE if ( ( q_arr [ i ] [ 1 ] + 1 ) < n ) : NEW_LINE INDENT sum [ q_arr [ i ] [ 1 ] + 1 ] -= d NEW_LINE DEDENT DEDENT arr [ 0 ] += sum [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT sum [ i ] += sum [ i - 1 ] NEW_LINE arr [ i ] += sum [ i ] NEW_LINE DEDENT DEDENT def printArray ( arr , n ) : NEW_LINE INDENT for i in arr : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 3 , 5 , 4 , 8 , 6 , 1 ] NEW_LINE q_arr = [ [ 0 , 3 ] , [ 4 , 5 ] , [ 1 , 4 ] , [ 0 , 1 ] , [ 2 , 5 ] ] NEW_LINE n = len ( arr ) NEW_LINE m = len ( q_arr ) NEW_LINE d = 2 NEW_LINE print ( " Original ▁ Array : " ) NEW_LINE printArray ( arr , n ) NEW_LINE incrementByD ( arr , q_arr , n , m , d ) NEW_LINE print ( " Modified Array : " ) NEW_LINE printArray ( arr , n ) NEW_LINE