Java Solution
\nclass Solution {\n    public long matrixSumQueries(int n, int[][] queries) {\n        long countRowsChanged = n;\n        boolean[] rowsChanged = new boolean[
```\nclass Solution {\n    public long matrixSumQueries(int n, int[][] queries) {\n        long countRowsChanged = n;\n        boolean[] rowsChanged = new boolean[n];\n        long countColsChanged = n;\n        boolean[] colsChanged = new boolean[n];\n        long result = 0;\n        for (int i = queries.length - 1; i >= 0; i--) {\n            int[] query = queries[i];\n            int type = query[0];\n            int index = query[1];\n            long value =  (long) query[2];\n            if (type == 0) {\n                if (rowsChanged[index]) {\n                    continue;\n                }\n                result = result + (long) (countColsChanged * value);\n                countRowsChanged--;\n                rowsChanged[index] = true;\n            } else {\n                if (colsChanged[index]) {\n                    continue;\n                }\n                result = result + (long) (countRowsChanged * value);\n                countColsChanged--;\n                colsChanged[index] = true;\n            }\n        }\n        return result;\n    }\n}\n```
['Java']