Clean Python 3, DP and heap, O(MN * logk)
Use a heap to maintain k largest elements.\nAnd for each cell, we can xor it with its top_left, top, and left elements to get its current value\nTime: O(MN * lo
Use a heap to maintain k largest elements.\nAnd for each cell, we can xor it with its top_left, top, and left elements to get its current value\nTime: `O(MN * logk)`\nSpace: `O(MN + k) = O(MN)`\n```\nimport heapq\nclass Solution:\n    def kthLargestValue(self, matrix: List[List[int]], k: int) -> int:\n        heap = []\n        for i, row in enumerate(matrix):\n            for j, cell in enumerate(row):\n                if i > 0:\n                    cell ^= matrix[i-1][j]\n                if j > 0:\n                    cell ^= matrix[i][j-1]\n                if i > 0 and j > 0:\n                    cell ^= matrix[i-1][j-1]\n                matrix[i][j] = cell\n                heapq.heappush(heap, cell)\n                if len(heap) > k: heapq.heappop(heap)\n        return heap[0]\n```\nIt can achieve `O(MN)` time by adopting quickselect of all elements. credit to [@ye15](https://leetcode.com/ye15/)
[]