Clean Solution w/ Explanation without using segment trees | Accepted | Beats 99%
\nclass NumArray {\n    vector<int> arr; //Initialising global array\n    int sum = 0; // Initialising global sum\npublic:\n    NumArray(vector<int>& nums) {\n 
```\nclass NumArray {\n    vector<int> arr; //Initialising global array\n    int sum = 0; // Initialising global sum\npublic:\n    NumArray(vector<int>& nums) {\n        for(int i=0;i<nums.size();i++)\n            arr.push_back(nums[i]), sum+=nums[i]; // storing elements in global array and calculating sum of elements - O(N)\n    }\n    \n    void update(int index, int val) {\n        sum += val - arr[index]; // Updating global sum with new value - O(1)\n        arr[index] = val; // Updating the val at index in global array - O(1)\n    }\n    \n    int sumRange(int left, int right) {\n        int res = 0;\n        if(right-left<arr.size()/2) {\n            res = accumulate(arr.begin()+left, arr.begin()+right+1, 0); //If range(left, right) is less than half of array length, then calculating sum from left to right - O(<N/2) [Precise]\n        } else {\n            res = sum - accumulate(arr.begin(), arr.begin()+left, 0) - accumulate(arr.begin()+right+1, arr.end(), 0); // /If range(left, right) is greater than half of array length, then calculating sumRange by subtracting sum from 0th index to left-1 and from right+1 to last index from the global sum.\n\t\t\t//i.e. sum - sum(0, left-1) - sum(right+1, n-1) where n is length of array\n        }\n        return res;\n    }\n};\n```\n\n
['Array', 'C', 'C++']