Easy solution
 # Intuition  \n\n\n# Approach\n\nTraverse from backward and add in the ans accordingly..\n\n# Code\n\nclass Solution {\npublic:\n    long long matrixSumQueries
<!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTraverse from backward and add in the ans accordingly..\n\n# Code\n```\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n        // cd - column done , rd - row done\n        vector<int> cd (n , 0) , rd(n , 0);\n        long long ans = 0;\n        int cnc = 0, cnr = 0;  // cnc-to store the col done count , cnr-to store the row done count \n        \n        \n        for(int i=queries.size()-1 ; i>=0 ; i--){\n            int type = queries[i][0];\n            int idx = queries[i][1];\n            int val = queries[i][2];\n            \n            if(type == 0){\n                if(rd[idx] == 0){\n                    ans += (n-cnc)*val;\n                    rd[idx] = 1;\n                    cnr++;\n               }\n            }\n            else if(type == 1){\n               if(cd[idx] == 0){\n                    ans += (n-cnr)*val;\n                    cd[idx] = 1;\n                    cnc++;\n               }\n            }\n        }\n        \n        return ans;\n    }\n};\n```
['C++']