Python | Reverse | O(n)
Code\n\nclass Solution:\n    def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int:\n        queries.reverse()\n        rows = set()\n        cols
# Code\n```\nclass Solution:\n    def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int:\n        queries.reverse()\n        rows = set()\n        cols = set()\n        res = 0\n        for t,i,val in queries:\n            if t == 0:\n                if i not in rows:\n                    res += val*(n-len(cols))\n                rows.add(i)\n            else:\n                if i not in cols:\n                    res += val*(n-len(rows))\n                cols.add(i)\n        return res\n        \n```
['Python3']