text: Sum of even values and update queries on an array | Function to return the sum of even elements after updating value at given index ; Add given value to A [ index ] ; To store the sum of even elements ; If current element is even ; Function to print result for every query ; Resultant vector that stores the result for every query ; Get sum of even elements after updating value at given index ; Store sum for each query ; Print the result for every query ; Driver code
code: def EvenSum ( A , index , value ) : NEW_LINE INDENT A [ index ] = A [ index ] + value NEW_LINE sum = 0 NEW_LINE for i in A : NEW_LINE INDENT if ( i % 2 == 0 ) : NEW_LINE INDENT sum = sum + i NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT def BalanceArray ( A , Q ) : NEW_LINE INDENT ANS = [ ] NEW_LINE i , sum = 0 , 0 NEW_LINE for i in range ( len ( Q ) ) : NEW_LINE INDENT index = Q [ i ] [ 0 ] NEW_LINE value = Q [ i ] [ 1 ] NEW_LINE sum = EvenSum ( A , index , value ) NEW_LINE ANS . append ( sum ) NEW_LINE DEDENT for i in ANS : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT A = [ 1 , 2 , 3 , 4 ] NEW_LINE Q = [ [ 0 , 1 ] , [ 1 , - 3 ] , [ 0 , - 4 ] , [ 3 , 2 ] ] NEW_LINE BalanceArray ( A , Q ) NEW_LINE