Greedy simple solution from the end with Set
Complexity\n- Time complexity: O(m)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\nwher
# Complexity\n- Time complexity: $$O(m)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\nwhere\n`n <= 10^4`\n`m = queries.length <= 5 * 10^4`\n\n# Code\n```python3 []\nclass Solution:\n    def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int:\n        calculated_rows = set()\n        calculated_cols = set()\n        result = 0\n        for type_, index, val in reversed(queries):\n            if type_ == 0 and index not in calculated_rows:\n                result += (n - len(calculated_cols)) * val\n                calculated_rows.add(index)\n                if len(calculated_rows) == n:\n                    break\n            elif type_ == 1 and index not in calculated_cols:\n                result += (n - len(calculated_rows)) * val\n                calculated_cols.add(index)\n                if len(calculated_cols) == n:\n                    break\n        return result\n```
['Hash Table', 'Math', 'Greedy', 'Python3']