SEGMENT TREE || C++
\nclass NumArray {\npublic:\n    vector<int> v,tree;\n    int n;\n    void buildtree(int s,int e,int x){\n        if(s==e){\n            tree[x] = v[s];\n      
```\nclass NumArray {\npublic:\n    vector<int> v,tree;\n    int n;\n    void buildtree(int s,int e,int x){\n        if(s==e){\n            tree[x] = v[s];\n            return;\n        }\n        int mid = (e-s)/2+s;\n        buildtree(s,mid,2*x+1);\n        buildtree(mid+1,e,2*x+2);\n        tree[x] = tree[2*x+1]+tree[2*x+2];\n    }\n    NumArray(vector<int>& nums) {\n        n = nums.size();\n        tree.resize(n*4,0);\n        v = nums;\n        buildtree(0,n-1,0);\n    }\n    void up1date(int s,int e,int x,int index,int val){\n        if(index<s||index>e){\n            return;\n        }\n        if(s==e){\n            if(s==index){\n                tree[x] = val;\n            }\n            return;\n        }\n        int mid = (e-s)/2+s;\n        up1date(s,mid,x*2+1,index,val);\n        up1date(mid+1,e,x*2+2,index,val);\n        tree[x] = tree[2*x+1]+tree[2*x+2];\n    }\n    void update(int index, int val) {\n        up1date(0,n-1,0,index,val);\n    }\n    int getsum(int l,int r,int s,int e,int x){\n        if(r<s||l>e){\n            return 0;\n        }\n        if(l<=s&&r>=e){\n            return tree[x];\n        }\n        int mid = (e-s)/2+s;\n        return getsum(l,r,s,mid,2*x+1)+getsum(l,r,mid+1,e,2*x+2);\n    }\n    int sumRange(int left, int right) {\n        return getsum(left,right,0,n-1,0);\n    }\n};\n ```
['Tree', 'C', 'C++']