Driver Code
int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int tree [ 4 * N + 5 ] = { 0 } ; build ( tree , arr , 0 , N - 1 , 0 ) ; int Q [ ] [ 3 ] = { { 2 , 0 , 3 } , { 1 , 1 , 5 } , { 2 , 1 , 2 } } ; int cntQuey = 3 ; for ( int 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 ) { cout << FindSum ( tree , 0 , N - 1 , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , 0 ) << " ▁ " ; } else { cout << - FindSum ( tree , 0 , N - 1 , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , 0 ) << " ▁ " ; } } } }