Driver Code
var arr = [ 1 , 2 , 3 , 4 ] ; var N = arr . length ; var tree = Array ( 4 * N + 5 ) . fill ( 0 ) ; build ( tree , arr , 0 , N - 1 , 0 ) ; var Q = [ [ 2 , 0 , 3 ] , [ 1 , 1 , 5 ] , [ 2 , 1 , 2 ] ] ; var cntQuey = 3 ; for ( var i = 0 ; i < cntQuey ; i ++ ) { if ( Q [ i ] [ 0 ] == 1 ) { update ( tree , 0 , 0 , N - 1 , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] ) ; } else { if ( Q [ i ] [ 1 ] % 2 == 0 ) { document . write ( FindSum ( tree , 0 , N - 1 , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , 0 ) + " " ) ; } else { document . write ( - FindSum ( tree , 0 , N - 1 , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , 0 ) + " " ) ; } } }