C++(Segment Tree Solution)
Please Upvote if You Like the Solution!\n\n    class NumArray {\n    public:\n    vectorst;\n    int n;\n     void buildTree(vector &arr , int start_index, int 
**Please Upvote if You Like the Solution!**\n\n    class NumArray {\n    public:\n    vector<int>st;\n    int n;\n     void buildTree(vector<int> &arr , int start_index, int start, int end)\n     {\n        if(start>end)\n            return;\n        if (start==end)\n        {\n            st[start_index] =arr[start]; \n            return;\n        }\n        int mid = (start+end)/2;\n        buildTree(arr, 2*start_index+1,start, mid);\n        buildTree(arr, 2*start_index+2, mid+1,end);\n         \n        st[start_index]=st[2*start_index+1]+ st[2*start_index+2];\n    }\n    \n    int Query(int qs,int qe,int start,int end, int start_index)\n    {\n        if (qs>end or qe<start) //No Overlap\n        { \n            return 0;\n        }\n        if (qs<=start && qe>=end)\n        { \n            return st[start_index];\n        }\n        // partial overlap\n        int middle=start+(end-start)/2;\n        int leftsum=Query(qs,qe,start,middle,2*start_index+1);\n        int rightsum=Query(qs,qe,middle+1,end,2*start_index+2);\n        \n        return leftsum+rightsum;\n    }\n     void Update(int start_index,int start,int end,int pos,int newvalue) \n     {\n        if(start>pos or end<pos) // no overlap\n            return;\n         \n        if(start==end)// total overlap\n        {\n            st[start_index]=newvalue;\n            return;\n        }\n\n        int middle=(start+end)/2;// partial overlap\n        Update(2*start_index+1,start,middle,pos,newvalue); // left child\n        Update(2*start_index+2,middle+1,end,pos,newvalue); // right child\n         \n        st[start_index]=st[2*start_index+1]+st[2*start_index+2];\n    }\n    NumArray(vector<int>& nums) \n    {\n        if(nums.size()==0)\n            return;\n            n = nums.size();\n            st.resize(4*n,0);  // Maximum size of a segment tree for an array of size n is 4n\n           \n        buildTree(nums,0, 0,n-1);\n    }\n    \n    void update(int index, int val)\n    {\n        Update(0,0,n-1,index,val);\n        \n    }\n    \n    int sumRange(int left, int right) \n    {\n        return Query(left, right, 0, n-1, 0); \n        \n    }\n};\n
['Tree', 'C', 'C++']