Python Segment Tree
\nclass TreeNode:\n    def __init__(self, start, end, sum=0, left=None, right=None):\n        self.start = start\n        self.end = end\n        self.sum = sum
```\nclass TreeNode:\n    def __init__(self, start, end, sum=0, left=None, right=None):\n        self.start = start\n        self.end = end\n        self.sum = sum\n        self.left = left\n        self.right = right\n\n\nclass NumArray:\n\n    def __init__(self, nums: List[int]):\n        self.root = self.build_tree(0, len(nums)-1, nums)\n\n    def update(self, i: int, val: int) -> None:\n        self.update_tree(self.root, i, val)\n\n    def sumRange(self, i: int, j: int) -> int:\n        return self.query_tree(self.root, i, j)\n        \n    def build_tree(self, start, end, nums):\n        if end < start:\n            return None\n        if start == end:\n            return TreeNode(start, end, nums[start])\n        mid = (start+end)//2\n        left = self.build_tree(start, mid, nums)\n        right = self.build_tree(mid+1, end, nums)\n        return TreeNode(start, end, left.sum+right.sum, left, right)\n    \n    def update_tree(self, node, index, val):\n        if node.start == node.end == index:\n            node.sum = val\n            return\n        mid = (node.start+node.end)//2\n        if index <= mid:\n            self.update_tree(node.left, index, val)\n        else:\n            self.update_tree(node.right, index, val)\n        node.sum = node.left.sum + node.right.sum\n        \n    def query_tree(self, node, start, end):\n        if node.start == start and node.end == end:\n            return node.sum\n        mid = (node.start+node.end)//2\n        if end <= mid:\n            return self.query_tree(node.left, start, end)\n        elif start > mid:\n            return self.query_tree(node.right, start, end)\n        else:\n            return self.query_tree(node.left, start, mid) + self.query_tree(node.right, mid+1, end)\n```
[]