C++ ||  Easy explanation || Min-heap (priority-queue)
Intuition\nWe need to find the Xor of all elements of the grid in the matrix[i][j] where i is <=a and j<=b. Notice that it\'s a rectangle area (for better clari
# Intuition\nWe need to find the Xor of all elements of the grid in the matrix[i][j] where i is <=a and j<=b. Notice that it\'s a rectangle area (for better clarity of the question).\nWe must find a way using which we can find xor at (x,y) using the previous computed values.\n\n# Approach\n\nFirst we find the xor of all elements in each row. This will acts as pre-computed values for the next row.\n\n![image.png](https://assets.leetcode.com/users/images/4385ae02-b389-4975-b659-6f109dbcc6fd_1718661428.2875855.png)\n\nThe answer for the (x,y) index will be matrix[x,y]^matrix[x-1,y].\n- The cell in row just above the (x,y) cell will contain the xor of the all cells in the (x-1,y) region. \n- And the cell at (x,y) contain the xor of the the elements in the x-th row.\n- So, Xor of matrix[x][y] ^ matrix[x-1][y] will give xor of all elements of the grid.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(m * n) for traversing the matrix.\nO(m * n * log(k)) since we are using the priority queue.\n\n\n# Code\n```\nclass Solution {\npublic:\n    int kthLargestValue(vector<vector<int>>& mt , int k) {\n        int m=mt.size();\n        int n=mt[0].size();\n\n        //This loop calculates the Xor of the elements in each row.\n       for(int i=0;i<m;i++)\n       {\n        for(int j=1;j<n;j++)\n        {\n            mt[i][j]=mt[i][j]^mt[i][j-1];\n        }\n       }\n\n       \n        //We now update the matrix inorder to find the answer to the (i,j) index.\n        for(int i=1;i<m;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                //Xor of current cell with the cell just above it.\n                mt[i][j]^=mt[i-1][j];\n            }\n        }\n        priority_queue<int, vector<int>, greater<int>> pq;\n\n        //Using min-heap to find the k-th largest element in the answer matrix\n        for(int i=0;i<m;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                pq.push(mt[i][j]);\n                if(pq.size()>k)\n                pq.pop();\n            }\n\n        }\n        return pq.top();\n\n    \n\n    \n    }\n};\n```
['C++']