Create segment tree of size 4 * n
ArrayList sum = new ArrayList ( ) ; ArrayList add = new ArrayList ( ) ; ArrayList ans = new ArrayList ( ) ; for ( int i = 0 ; i < ( n << 2 ) ; i ++ ) { sum . Add ( 0 ) ; add . Add ( 0 ) ; }