```
class NumArray {
private:
int n;
vector<int> nums;
vector<int> sums;
public:
NumArray(vector<int> &nums) {
n = nums.size();
nums = nums;
int tmp = 0;
for (int i = 0; i < n; i++) {
tmp += nums[i];
sums.push_back(tmp);
}
}
int sumRange(int i, int j) {
if (i == 0) return sums[j];
else return (sums[j]-sums[i-1]);
}
};
```