🔥 ✅Self Explanatory, Intuitive & Easy to Understand C++ Code ✅🔥
Intuition\nIf you execute the given queries in reverse order the upcoming query will not be able to override the changes done boy the previously  executed queri
# Intuition\nIf you execute the given queries in reverse order the upcoming query will not be able to override the changes done boy the previously  executed queries.\n\n# Approach\nCode is self explanatory.\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n        vector<bool> row(n, false), col(n, false);\n        int rowc = n, colc = n;\n        long long sum = 0;\n\n        for(int i = queries.size() - 1; i >= 0 && rowc + colc > 0; i--) {\n            int type = queries[i][0], idx = queries[i][1], val = queries[i][2];\n\n            if(type == 0) {\n                if(!rowc || row[idx]) continue;\n                colc--;\n                row[idx] = true;\n                sum += rowc * val;\n            } else if(type == 1) {\n                if(!colc || col[idx]) continue;\n                rowc--;\n                col[idx] = true;\n                sum += colc * val;\n            }\n        }\n        return sum;\n    }\n};\n```
['C++']