Python Elegant & Short | O(n) | Hash Map
Complexity\n- Time complexity: O(m), where m - length of queries\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n    def matrixSumQueries(self, n: int, 
# Complexity\n- Time complexity: $$O(m)$$, where $$m$$ - length of ```queries```\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n    def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int:\n        used_cols = set()\n        used_rows = set()\n\n        # Initially matrix filled with zeros\n        queries_sum = 0\n\n        for op, idx, val in reversed(queries):\n            # Fills an untouched row\n            if op == 0 and idx not in used_rows:\n                queries_sum += val * (n - len(used_cols))  # Column may have already filled cells with other rows\n                used_rows.add(idx)\n            # Fills an untouched column\n            elif op == 1 and idx not in used_cols:\n                queries_sum += val * (n - len(used_rows))  # Row may have already filled cells with other columns\n                used_cols.add(idx)\n\n        return queries_sum\n```
['Hash Table', 'Python', 'Python3']