Segment Tree & Binary Indexed Tree Solution [C++]
Segment Trees Solution :-\n\n\nclass segmentTree {\npublic:\n    int sum, start, end;\n    segmentTree *left, *right;\n    segmentTree (int start, int end) {\n 
Segment Trees Solution :-\n\n```\nclass segmentTree {\npublic:\n    int sum, start, end;\n    segmentTree *left, *right;\n    segmentTree (int start, int end) {\n        this->start = start;\n        this->end = end;\n        this->left = nullptr;\n        this->right = nullptr;\n        this->sum = 0;\n    }\n};\nclass NumArray {\npublic:\n    segmentTree* root = nullptr;\n    \n    segmentTree* buildTree(vector<int>& nums, int s, int e) {\n        if (s > e) {\n            return nullptr;\n        } else {\n            //for range s and e!\n            segmentTree* ret = new segmentTree(s, e);\n            if (s == e) {\n                ret->sum = nums[s];\n            } else {\n                int mid = s  + (e - s) / 2;             \n                ret->left = buildTree(nums, s, mid);\n                ret->right = buildTree(nums, mid + 1, e);\n                //this is the condition where we can change, if we want to evaluate gcd, then instead of sum, we can evaluate gcd of left and right!\n                ret->sum = ret->left->sum + ret->right->sum;\n            }         \n            return ret;\n        }\n    }\n    \n    NumArray(vector<int>& nums) {\n        root = buildTree(nums, 0, nums.size() - 1);\n    }\n    \n    void update(int i, int val) {\n        update(root, i, val);\n    }\n    \n    void update(segmentTree* root, int pos, int val) {\n        if (root->start == root->end) {\n           root->sum = val;\n        } else {\n            int mid = root->start + (root->end - root->start) / 2;\n            if (pos <= mid) {\n                 update(root->left, pos, val);\n            } else {\n                 update(root->right, pos, val);\n            }\n            //this is the condition where we can change, if we want to evaluate gcd, then instead of sum, we can evaluate gcd of left and right!\n            root->sum = root->left->sum + root->right->sum;\n        }\n    }\n    \n    int sumRange(int i, int j) {\n        return sumRange(root, i, j);\n    }\n    int sumRange(segmentTree* root, int start, int end) {\n        if (root->end == end && root->start == start) {\n            return root->sum;\n        } else {\n            int mid = root->start + (root->end - root->start) / 2;\n            if (end <= mid) {\n                return sumRange(root->left, start, end);\n            } else if (start >= mid+1) {\n                return sumRange(root->right, start, end);\n            }  else {\n                return sumRange(root->right, mid+1, end) + sumRange(root->left, start, mid);\n            }\n        }\n    }\n};\n\n```\n\n\n\nBinary Indexed Tree :-\n\n```\nclass NumArray {\npublic:\n    vector<int> bittree, num;\n    void init(int i, int val) {\n        i = i + 1;\n        while(i <= bittree.size() - 1) {\n            bittree[i] += val;\n            i += i & (-i);\n        }\n    }\n    int getsum(int i) {\n        i = i + 1;\n        int sum = 0;\n        while(i > 0) {\n            sum += bittree[i];\n            i -= i & (-i);\n        }\n        return sum;\n    }\n    NumArray(vector<int>& nums) {\n        num = nums;\n        bittree.resize(nums.size() + 1, 0);\n        for(int i = 0; i < nums.size(); i++) {\n            init(i, nums[i]);\n        }\n    }\n    \n    void update(int i, int val) {\n        int diff = val - num[i];\n\t\tnum[i] = val;\n\t\tinit(i, diff);\n    }\n    \n    int sumRange(int i, int j) {\n        return getsum(j) - getsum(i -1);\n    }\n};\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray* obj = new NumArray(nums);\n * obj->update(i,val);\n * int param_2 = obj->sumRange(i,j);\n */\n```
['Tree', 'Binary Indexed Tree', 'C', 'Binary Tree', 'C++']