c++ prefix sum in each row & each column
\n# Code\n\nclass Solution {\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        //basically the idea is to get ma
\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        //basically the idea is to get mat[i][j]th element by its prefix sum so for each query we we increase top left by one & check if bottom+1 & right+1 is valid if its we increase by 1 if not we decrease value ou bottom+1,left & bottom,left+1 by 1 \n    vector<vector<int>>mat(n,vector<int>(n,0));\n        for(int i=0;i<queries.size();i++){\n            int r1=queries[i][0],r2=queries[i][2],c1=queries[i][1],c2=queries[i][3];\n            mat[r1][c1]+=1;\n            if(r2+1<n && c2+1<n)mat[r2+1][c2+1]+=1;//increase value of next element diagonally\n            if(r2+1<n)mat[r2+1][c1]-=1;//decreasing value of next element in same column\n            if(c2+1<n)mat[r1][c2+1]-=1;//decreasing value of next element in same row\n        }\n        for(int i=0;i<n;i++){\n            for(int j=1;j<n;j++){\n                mat[i][j]+=mat[i][j-1];\n            }\n        }\n        for(int i=0;i<n;i++){\n            for(int j=1;j<n;j++){\n                mat[j][i]+=mat[j-1][i];\n            }\n        }\n        return mat;\n    }\n};\n\n\n\n```
['Prefix Sum', 'C++']