100% beats Easy to understand in java
Intuition\n \n Dont FALL in a trap of traversing queries from start to end.\n\n# Approach\n \nTraverse the queries from end to start then have a visited array f
# Intuition\n<!--  -->\n Dont FALL in a trap of traversing queries from start to end.\n\n# Approach\n<!--   -->\nTraverse the queries from end to start then have a visited array for both col and row then its a matter of updating the values from end.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\no(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\no(n)\n# Code\n```java []\nclass Solution {\n    public long matrixSumQueries(int n, int[][] q) {\n        boolean[] row = new boolean[n]; // mark rows that are deleted. true meas deleted\n        boolean[] col = new boolean[n]; // mark columns that are deleted. true meas deleted\n        int rowRemain = n; // count the number of rows that are not deleted\n        int colRemain = n; // count the number of columns that are not deleted\n        long ans = 0;\n        for (int i = q.length - 1; i >= 0; --i) {\n            int type = q[i][0], index = q[i][1], value = q[i][2];\n            if (type == 0) {\n                if (!row[index]) { // the row has not been deleted\n                    // only not deleted columns contribute to the final sum\n                    ans += value * colRemain;\n                    row[index] = true; // mark this row is deleted\n                    --rowRemain; // decrease the number of not deleted rows\n                }\n            } else {\n                if (!col[index]) { // the column has not been deleted\n                    // only not deleted rows contribute to the final sum\n                    ans += value * rowRemain;\n                    col[index] = true; // mark this column is deleted\n                    --colRemain; // decrease the number of not deleted columns\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']