prefix sum 2d array O(n*m)
\n\n# Code\n\nclass Solution {\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        vector<vector<int>> arr(n+1, ve
\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        vector<vector<int>> arr(n+1, vector<int>(n+1));\n        for (auto& q : queries) {\n            arr[q[0]][q[1]]++, arr[q[0]][q[3] + 1]--;\n            arr[q[2] + 1][q[1]]--, arr[q[2] + 1][q[3] + 1]++;\n        }\n        \n        for (int i = 0; i < n; i++) \n            for (int j = 1; j < n; j++)  arr[i][j] += arr[i][j - 1];\n        for (int i = 1; i < n; i++) \n            for (int j = 0; j < n; j++)  arr[i][j] += arr[i - 1][j];\n        vector<vector<int>> ans(n,vector<int>(n));\n        for(int i= 0;i<n;i++){\n            for(int j = 0;j<n;j++)ans[i][j] = arr[i][j];\n        }\n        return ans;\n    }\n};\n```
['C++']