Easy Java || Fast || Beginner friendly
\nclass Solution {\n    public long matrixSumQueries(int n, int[][] query) {\n      int[][] res = new int[n][2];\n        long answer = 0;\n\n        for (int i
```\nclass Solution {\n    public long matrixSumQueries(int n, int[][] query) {\n      int[][] res = new int[n][2];\n        long answer = 0;\n\n        for (int i = 0; i < n; i++) {\n            res[i][0] = 1;\n            res[i][1] = 1;\n        }\n        int cr = 0, cc = 0;\n\n        for (int i = query.length - 1; i >= 0; i--) {\n            if (res[query[i][1]][query[i][0]] != 0) {\n                if (query[i][0] == 0) {\n                    cr++;\n                } else {\n                    cc++;\n                }\n                answer += (n - (query[i][0] == 0 ? cc : cr)) * query[i][2];\n                res[query[i][1]][query[i][0]] = 0;\n            }\n        }\n        return answer;\n    }\n}\n```
['Array', 'Java']