C++ line sweep
Intuition\nMark the start and end of each query and generate the res by doing the prefix sum once.\n\n# Approach\n\n# Complexity\n- Time complexity:\nO(q + n^2)
# Intuition\nMark the start and end of each query and generate the res by doing the prefix sum once.\n\n# Approach\n\n# Complexity\n- Time complexity:\n$$O(q + n^2)$$, where q is the size of the queries\n\n- Space complexity:\n$$O(n^2)$$\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        vector<vector<int>> res(n, vector<int>(n));\n        for(auto q: queries) {\n            res[q[0]][q[1]] += 1;\n            if(q[2]+1 < n && q[3]+1 < n) res[q[2]+1][q[3]+1] += 1;\n            if(q[3]+1 < n) res[q[0]][q[3]+1] -= 1;\n            if(q[2]+1 < n) res[q[2]+1][q[1]] -= 1;\n        }\n        for(auto &r: res) {\n            int cur = 0;\n            for(auto &v: r) {\n                v += cur;\n                cur = v;\n            }\n        }\n        for(int i=0; i<n; i++) {\n            int cur = 0;\n            for(int j=0; j<n; j++) {\n                res[j][i] += cur;\n                cur = res[j][i];\n            }\n        }\n        return res;\n    }\n};\n```
['C++']