Clear and Concise Solution
Complexity\n- Time complexity: O(queries.length)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(queries.length)\n Add your space complexit
# Complexity\n- Time complexity: $$O(queries.length)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(queries.length)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python\nclass Solution:\n    def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int:\n        res, rows, cols = 0, set(), set()\n        while queries:\n            col, i, val = queries.pop()\n            if col and i not in cols:\n                res += val * (n - len(rows))\n                cols.add(i)\n            elif not col and i not in rows:\n                res += val * (n - len(cols))\n                rows.add(i)\n        return res\n\n```
['Python3']