Beats 83.53% in JAVA, Clean code, Beautiful and Intuitive Approach
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public long matrixSumQueries(int n, int[][] queries) {\n        int len = queries.length, rowsrem = n, colsrem = n;\n        long ans = 0;\n        boolean rows[] = new boolean[n];\n        boolean cols[] = new boolean[n];\n        for(int i = len - 1; i >= 0; i--){\n            int signal = queries[i][0];\n            int index = queries[i][1];\n            int val = queries[i][2];\n            if(signal == 0){\n                if(!rows[index]){\n                    ans += val*colsrem;\n                    rows[index] = true;\n                    rowsrem --;\n                }\n            }else{\n                if(!cols[index]){\n                    ans += val*rowsrem;\n                    cols[index] = true;\n                    colsrem --;\n                }\n            }\n            if(colsrem == 0 && rowsrem == 0){\n                break;\n            }\n        }\n        return ans;\n    }\n}\n```
['Java']