Easy || Short || Conversion from brute force to Optimized
Intuition\nFirst i tried to apply the brute force but after successfully failing on 12/30 testcases what i was clear about was that i have to make the complexit
# Intuition\nFirst i tried to apply the brute force but after successfully failing on 12/30 testcases what i was clear about was that i have to make the complexity from O(10^4*500*500) to O(10^4*500)\n\n# Approach\nOther than changing the values of all the rows just increment the first index of each row and decrement the index after the last element of each row.\nBy this if at last if we change an array to prefix sum then it will assign all the required values at once.\n\n# Complexity\n- Time complexity: O(n*q)\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        vector<vector<int>>v(n,vector<int>(n,0));\n        for(auto& i:queries){\n            for(int k=i[0];k<=i[2];k++)\n                v[k][i[1]]++; if((i[3]+1)<n) v[k][i[3]+1]--;    \n        }\n        for(int i=0;i<n;i++) for(int j=1;j<n;j++) v[i][j]+=v[i][j-1];\n        return v;\n    }\n};\n```
['C++']