Using Bit Indexed Tree
\n//Using Fenwick Tree\nclass NumArray {\n    private:\n    vector<int> _nums, bit; //declare _nums vector and fenwick (or) bit vector\n    int lower_bit(int i)
```\n//Using Fenwick Tree\nclass NumArray {\n    private:\n    vector<int> _nums, bit; //declare _nums vector and fenwick (or) bit vector\n    int lower_bit(int i){\n        return i&-i;        //returns rightmost setBit\n    }\n    void add(int i,int val){\n        ++i;\n        while(i<bit.size()){\n            bit[i] += val;      //adds val to the fenwick tree\n            i += lower_bit(i);\n        }\n    }\n    int query(int i){\n        int sum{};\n        ++i;\n        while(i){\n            sum += bit[i];      //return query for index i\n            i -= lower_bit(i);\n        }\n        return sum;\n    }\npublic:\n    NumArray(vector<int>& nums): _nums(nums) {\n        bit.resize(nums.size()+1);\n        //preprocessing for BIT\n        for(int i=0;i<_nums.size();++i)\n            add(i, _nums[i]);\n    }\n    \n    void update(int index, int val) {\n        if(val!=_nums[index]){\n            add(index, val-_nums[index]);   //executes only if the given val isn\'t equal to the val present in the _nums vector\n            _nums[index]=val;\n        }\n    }\n    \n    int sumRange(int left, int right) {\n        return query(right)-query(left-1);  //returns prefix sum\n    }\n};\n\n/**\n * Your NumArray object will be instantiated and called as such:\n * NumArray* obj = new NumArray(nums);\n * obj->update(index,val);\n * int param_2 = obj->sumRange(left,right);\n */\n```
['Tree', 'C']