Prefix Sum | C++
\n\n# Code\n\nclass Solution {\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        vector<vector<int>> mat(n,vecto
\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        vector<vector<int>> mat(n,vector<int>(n,0));\n        for(auto &p : queries) {\n            int x1 = p[0] ,y1 = p[1],x2 = p[2] ,y2 = p[3]; \n            for(int i=x1;i<=x2;i++) {\n                mat[i][y1]++;\n                // if next column is out of matrix \n                // mark the next row as negative\n                if((y2+1) >= n) {\n                    if(i+1 < n) mat[i+1][0] -= 1;\n                    else continue;\n                } else {\n                    mat[i][y2+1] -= 1;\n\n                }\n            }\n        }   \n        int temp = 0;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++) {\n                temp += mat[i][j];\n                mat[i][j] = temp;\n            }\n        }\n        return mat;\n    }\n};\n```\n# Please Upvote if like the solution
['Prefix Sum', 'C++']