SIMPLE || C++
Code\n\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& v) {\n        long long int ans = 0;\n        int a = n, b = n;\n 
# Code\n```\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& v) {\n        long long int ans = 0;\n        int a = n, b = n;\n        vector<int> c(b,0),r(n,0);\n        reverse(v.begin(),v.end());//traverse from back\n        for(auto &i: v){\n            cout<<a<<" "<<b<<endl;\n            if(i[0]){\n                if(a>0){\n                    if(c[i[1]]>0)continue;\n                    ans += i[2]*1LL*a;\n                    c[i[1]] = i[2];\n                }\n                b--;\n            }else{\n                if(b>0){\n                    if(r[i[1]]>0)continue;\n                    ans += i[2]*1LL*b;\n                    r[i[1]] = i[2];\n                }\n                a--;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']