def segment_tree_range_sum_query (tree, l, r):
    """The function tells the sum of elements in a given range using the segment tree in O(log(n))
        input : segment tree, array starting and ending index of range
        returns the sum of elements of array in that range"""

    m = len(tree)
    l,r = l+m//2, r+m//2    # converting array index to segment tree index
    rsum = 0
    while (l<=r) :          # while the lower and upper limit do not cross each other
        if l%2 == 1:        # if lower range index is a right child, add that and jump to next index (towards right)
            rsum += tree[l]
            l += 1
        if r%2 == 0:        # if upper range index is a left child, add that and jump to next index (towards left)
            rsum += tree[r]
            r -= 1

        l, r = l//2, r//2       # both the indices are have a common ancestor in tree, so move up, till that ancestor
        
    return rsum