Segment Tree || C++ Solution || Commented code for easy understanding :)
Upvote if It helps :)\n\n\nclass NumArray {\nprivate:\n    void build(vector<int> &nums,int idx,int low,int high){\n        // Base case\n        if(low == high
**Upvote if It helps :)**\n\n```\nclass NumArray {\nprivate:\n    void build(vector<int> &nums,int idx,int low,int high){\n        // Base case\n        if(low == high){\n            seg[idx] = nums[low];\n            return;\n        }\n\n        int mid = low + (high - low) / 2;\n        build(nums,2*idx+1,low,mid);\n        build(nums,2*idx+2,mid+1,high);\n        seg[idx] = seg[2*idx+1] + seg[2*idx+2];\n    }\n\n    int updateseg(int idx,int low,int high,int targetIdx,int val){\n        // inside the of range\n        if(low == targetIdx && high == targetIdx){\n            return seg[idx] = val;\n        }\n\n        // Case 2 : if inside the range completly\n        if(low > targetIdx || high < targetIdx) return seg[idx];\n\n        // Case 3 : if not inside the range completly\n        int mid = low + (high - low) / 2;\n\n        int left = updateseg(2*idx+1,low,mid,targetIdx,val);\n        int right = updateseg(2*idx+2,mid+1,high,targetIdx,val);\n        seg[idx] = left + right;\n        return seg[idx];\n    }\n\n    int query(int idx,int low,int high,int l,int r){\n        // Case 1 : if inside the range completely\n        if(low >= l && high <= r){\n            return seg[idx];\n        }\n\n        // Out of range\n        if(low > r || high < l) return 0;\n\n        // Case 3 : if not inside the range completly\n        int mid = low + (high - low) / 2;\n\n        int left = query(2*idx+1,low,mid,l,r);\n        int right = query(2*idx+2,mid+1,high,l,r);\n\n        return left + right;\n    }\npublic:\n    vector<int> arr, seg;\n    int n;\n    NumArray(vector<int>& nums) {\n        n = nums.size();\n        seg.resize(4*n+1);\n        build(nums,0,0,n-1);\n    }\n    \n    void update(int index, int val) {\n        updateseg(0,0,n-1,index,val);\n    }\n    \n    int sumRange(int left, int right) {\n        int ans = query(0,0,n-1,left,right);\n        return ans;\n    }\n};\n\n```
['Segment Tree', 'C++']