O(M) - M is no of queries
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n        int remRows = n;\n        int remCols = n;\n\n        vector<bool> rowsDeleted(n,false);\n        vector<bool> colsDeleted(n,false);\n\n        reverse(queries.begin(),queries.end());\n        long long ans = 0;\n\n        for(auto query : queries) {\n            int rowOrCol = query[0];\n            if(rowOrCol == 0) {\n                int rowIdx = query[1];\n                int val = query[2];\n                if(!rowsDeleted[rowIdx]) {\n                    ans = ans + (remCols*val);\n                    remRows--;\n                    rowsDeleted[rowIdx] = true;\n                }\n            } else {\n                int colIdx = query[1];\n                int val = query[2];\n                if(!colsDeleted[colIdx]) {\n                    ans = ans + (remRows*val);\n                    remCols--;\n                    colsDeleted[colIdx] = true;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']