C++ | Greedy |  Easy and Short Solution
Intuition\nBy reading problem statement it look simple greedy with optimized brute force problem.\n\n# Approach\n- Start iterating from the end, while keeping t
# Intuition\nBy reading problem statement it look simple greedy with optimized brute force problem.\n\n# Approach\n- Start iterating from the end, while keeping track of the count of assignable rows and columns.\n- When performing a column operation, multiply the value by the remaining number of rows and add it to the answer. When performing a row operation, multiply the value by the remaining number of columns and add it to the answer.\n- Decrease the count of remaining rows when a row operation is performed, and decrease the count of remaining columns when a column operation is performed.\n\n# Complexity\n- Time complexity: \n  `O(q)` where q is number of queries.\n\n- Space complexity:\n  `O(n)` where n is number of rows/colums. \n\n\n# Code\n```\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& ques) {\n        vector<int> row(n,0), col(n,0); \n        int rfill = 0, cfill = 0,ind;\n        long long val,sum = 0;\n\n        for(int i = ques.size()-1; i>=0;--i){\n            ind = ques[i][1];\n            val = ques[i][2];\n            if(ques[i][0] == 0){\n                if(!row[ind]){\n                    sum += val * (n-cfill);\n                    ++rfill;\n                    row[ind] = val;\n                }\n            }else{\n                if(!col[ind]){\n                    sum += val * (n-rfill);\n                    ++cfill;\n                    col[ind] = val;\n                }\n            }\n        }\n\n        return sum;\n    }\n};\n```
['Greedy', 'C++']