Good question with simple and readable solution! #O(n) time and #O(n) space
Complexity\n- Time complexity: O(n)\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\n# Co
# Complexity\n- Time complexity: O(n)\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\n# Code\n```\n\nclass Solution:\n    def matrixSumQueries(self, n: int, queries: List[List[int]]) -> int:\n\n        # make dictionary with default value of [1,1] where first\n        # value represents whether type 0 is processed or not.\n        # Similarly, second value represents whether type 1 is\n        # processed or not\n        d = defaultdict(lambda: [1,1])\n\n        # stores the summation of vlaues of matrix entries\n        ans = 0\n\n        # cr, cc denotes number of rows / columns processed\n        cr, cc = 0, 0\n\n        # start query from reversed fashion as we know the fact we can overwrite the\n        # values\n        for x, y, z in reversed(queries):\n\n            # For index = y and type = x, process the matrix and\n            # later, make the value to 0.\n            # (Remember, we move in reversed manner)\n            # Eg. for a particular query with index y and type 0,\n            # we made d[y] = [0,1], so that we\'ve liabilty to process\n            # index y with type 1 as it is set to 1\n            if d[y][x]:\n                # x = 0 means type 0, so increment row\'s count\n                if x == 0:\n                    cr += 1\n                # x = 1 means type 1, so increment col\'s count\n                else:\n                    cc += 1\n\n                # while processing yth row, we\'ve to remove those columns which are\n                # already processed\n                if x == 0:\n                    remaining = n - cc\n                # while processing yth col, we\'ve to remove those rows which are\n                # already processed\n                else:\n                    remaining = n - cr\n\n                # multiply with value to get the desired result and add to variable ans    \n                ans += remaining * z\n\n                # since, we process the yth row / col depend upon type i.e. x, we can\n                # now mark to 0 (Remember, we move in reversed manner)\n                d[y][x] = 0\n\n        return ans\n```
['Python3']