C++ | O(Queries.size()) | Reverse Traversal
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 {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n        // int count = 0;\n        long long sol = 0;\n        int row = n;\n        int col = n;\n        vector<vector<int>>vis(n+1,vector<int>(3,0));\n       for(int i=queries.size()-1;i>=0;i--)\n       {\n           int a = queries[i][0];\n           int b = queries[i][1];\n           int c = queries[i][2];\n           if(vis[b][a])continue;\n           vis[b][a] = 1;\n           if(a==1)\n           {\n               // cout<<c<<" "<<row<<endl;;\n               sol+=(long long)c*row;\n               col--;\n           }\n           else\n           {\n               // cout<<c<<" "<<col<<endl;\n               sol+=(long long)c*col;\n               row--;\n               \n           }\n       }\n        return sol;\n        // vector<vector<int>>ans(n+1,vector<int>(n+1,0));\n        // for(int i=0;i<n;i++){\n        //     for(int j=0;j<n;j++)\n        //     {\n        //         auto x = row[i];\n        //         auto y = col[j];\n        //         if(x.first > y.first)\n        //         {\n        //             ans[i][j]  = x.second;\n        //         }\n        //         else\n        //         {\n        //             ans[i][j] = y.second;\n        //         }\n        //     }\n        // }\n        // long long sol = 0;\n        // for(int i=0;i<n;i++)\n        // {\n        //     for(int j=0;j<n;j++)\n        //     {\n        //         sol+=(long long)ans[i][j];\n        //     }\n        // }\n        // return sol;\n        \n    }\n};\n```
['C++']