[C++] Clean solution with comments
Approach\nThe idea is to fill-out a table row by row.\nFirst row is filled-out in a brute force way by deriving all the values from input queries.\nFor any othe
# Approach\nThe idea is to fill-out a table row by row.\nFirst row is filled-out in a brute force way by deriving all the values from input queries.\nFor any other row, for a given cell the value is computed as:\n1. Take the value from the cell above.\n2. Subtract number of queries (squares) which end in the cell above. They no longer cover current cell.\n3. Add number of queries (squares) which start in the current cell.\n\n# Complexity\n- Time complexity:\nO(n*m) + O(n*n)\n\n- Space complexity:\nO(n*n)\n\n# Code\n```\nclass Solution {\nprivate:\n    struct Sq{\n        int start_i;\n        int start_j;\n        int end_i;\n        int end_j;\n    };\n\npublic:\n    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {\n        // Store all query squares.\n        vector<Sq> sqs;\n        for(const auto &query : queries) {\n            sqs.push_back(Sq{.start_i = query[0], .start_j = query[1], .end_i = query[2], .end_j = query[3]});\n        }\n        \n        // How many squares start at a given cell?\n        vector<vector<int>> starting(n, vector<int>(n, 0));\n        // How many squares end at a given cell?\n        vector<vector<int>> ending(n, vector<int>(n, 0));\n        // Result\n        vector<vector<int>> res(n, vector<int>(n, 0));\n        \n        for(const auto &sq : sqs) {\n            // Fill out \'starting\'\n            for(int j = sq.start_j; j<=sq.end_j; ++j) {\n                starting[sq.start_i][j]+=1;\n            }\n            // Fill out \'ending\'\n            for(int j = sq.start_j; j<=sq.end_j; ++j) {\n                ending[sq.end_i][j]+=1;\n            }\n            // Fill out first row of the result.\n            if(sq.start_i == 0) {\n                for(int j = sq.start_j; j<=sq.end_j; ++j) {\n                    res[0][j]+=1;\n                }\n            }\n        }\n        \n        // Iterate over each cell starting from row #1.\n        for(int i = 1; i<n; ++i) {\n            for(int j = 0; j<n; ++j) {\n                // Take a value from the cell above, subtract squares which end above and add squares which start in the current cell.\n                res[i][j] = res[i-1][j] - ending[i-1][j] + starting[i][j];\n            }\n        }\n        \n        return res;\n    }\n};\n```
['C++']