Python: Well commented solution using Segment Trees
This solution is based on the top voted solution by  2guotou, which is in Java.\n\n    """\n        The idea here is to build a segment tree. Each node stores t
This solution is based on the top voted solution by  2guotou, which is in Java.\n\n    """\n        The idea here is to build a segment tree. Each node stores the left and right\n        endpoint of an interval and the sum of that interval. All of the leaves will store\n        elements of the array and each internal node will store sum of leaves under it.\n        Creating the tree takes O(n) time. Query and updates are both O(log n).\n    """\n    \n    #Segment tree node\n    class Node(object):\n        def __init__(self, start, end):\n            self.start = start\n            self.end = end\n            self.total = 0\n            self.left = None\n            self.right = None\n            \n    \n    class NumArray(object):\n        def __init__(self, nums):\n            """\n            initialize your data structure here.\n            :type nums: List[int]\n            """\n            #helper function to create the tree from input array\n            def createTree(nums, l, r):\n                \n                #base case\n                if l > r:\n                    return None\n                    \n                #leaf node\n                if l == r:\n                    n = Node(l, r)\n                    n.total = nums[l]\n                    return n\n                \n                mid = (l + r) // 2\n                \n                root = Node(l, r)\n                \n                #recursively build the Segment tree\n                root.left = createTree(nums, l, mid)\n                root.right = createTree(nums, mid+1, r)\n                \n                #Total stores the sum of all leaves under root\n                #i.e. those elements lying between (start, end)\n                root.total = root.left.total + root.right.total\n                    \n                return root\n            \n            self.root = createTree(nums, 0, len(nums)-1)\n                \n        def update(self, i, val):\n            """\n            :type i: int\n            :type val: int\n            :rtype: int\n            """\n            #Helper function to update a value\n            def updateVal(root, i, val):\n                \n                #Base case. The actual value will be updated in a leaf.\n                #The total is then propogated upwards\n                if root.start == root.end:\n                    root.total = val\n                    return val\n            \n                mid = (root.start + root.end) // 2\n                \n                #If the index is less than the mid, that leaf must be in the left subtree\n                if i <= mid:\n                    updateVal(root.left, i, val)\n                    \n                #Otherwise, the right subtree\n                else:\n                    updateVal(root.right, i, val)\n                \n                #Propogate the changes after recursive call returns\n                root.total = root.left.total + root.right.total\n                \n                return root.total\n            \n            return updateVal(self.root, i, val)\n    \n        def sumRange(self, i, j):\n            """\n            sum of elements nums[i..j], inclusive.\n            :type i: int\n            :type j: int\n            :rtype: int\n            """\n            #Helper function to calculate range sum\n            def rangeSum(root, i, j):\n                \n                #If the range exactly matches the root, we already have the sum\n                if root.start == i and root.end == j:\n                    return root.total\n                \n                mid = (root.start + root.end) // 2\n                \n                #If end of the range is less than the mid, the entire interval lies\n                #in the left subtree\n                if j <= mid:\n                    return rangeSum(root.left, i, j)\n                \n                #If start of the interval is greater than mid, the entire inteval lies\n                #in the right subtree\n                elif i >= mid + 1:\n                    return rangeSum(root.right, i, j)\n                \n                #Otherwise, the interval is split. So we calculate the sum recursively,\n                #by splitting the interval\n                else:\n                    return rangeSum(root.left, i, mid) + rangeSum(root.right, mid+1, j)\n            \n            return rangeSum(self.root, i, j)\n                    \n    \n    \n    # Your NumArray object will be instantiated and called as such:\n    # numArray = NumArray(nums)\n    # numArray.sumRange(0, 1)\n    # numArray.update(1, 10)\n    # numArray.sumRange(1, 2)
['Python']