Reverse order is the key | c++
Approach\nApply the queries in reverse order by carrying the number of rows and cols available, it is very straighfoward to update these values.\n# Complexity\n
# Approach\nApply the queries in reverse order by carrying the number of rows and cols available, it is very straighfoward to update these values.\n# Complexity\n- Time complexity:\n- $O(|queries|)$\n\n# Code\n```\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n        long long ans = 0; \n        long long R= n,C =n;\n        vector<bool> Rused(n),Cused(n);\n        \n        int M = queries.size();\n        for(int i = M-1;i>=0;i--){\n            int t = queries[i][0];     \n            int id = queries[i][1];      \n            long long x = queries[i][2];      \n            \n            if(t == 0){\n                if(Rused[id])continue;\n                ans += C*x;\n                Rused[id] = true;\n                R--;\n            }\n            else{\n                if(Cused[id])continue;\n                ans += R*x;\n                Cused[id] = true;\n                C--;\n            }\n            \n        }\n        return ans;\n    }\n};\n```
['C++']