C++ || Greedy || ✅ Easy and Short Solution
Approach \n- Updation of the most recent query\n\n# Complexity\n- Time complexity: O(n)\n\n\n# Code\n\nclass Solution {\npublic:\n    long long matrixSumQueries
# Approach \n- Updation of the most recent query\n\n# Complexity\n- Time complexity: O(n)\n\n\n# Code\n```\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& q) {\n        long long ans=0;\n        long long r=0,c=0;\n        vector<int>row(n+1),col(n+1);\n        // Here we are eliminating all the repeating queries and just keeping the most recent query\n        // We are eliminating query by changing the type of the query\n        for(int i=q.size()-1;i>=0;i--){\n            if(q[i][0]==0){\n                if(row[q[i][1]]!=0) q[i][0]=2;\n                else row[q[i][1]]=1;\n            }\n            else{\n                if(col[q[i][1]]!=0) q[i][0]=2;\n                else col[q[i][1]]=1;                \n            }\n        }\n        // Just adding the complete val*n and subtracting all the previous values that have been put into rows \n        // if the query is of column and vice versa\n        for(auto& i:q){\n            if(i[0]==0){               \n                r+=i[2];\n                ans+= i[2]*n;\n                ans-=c; \n            }\n            else if(i[0]==1){\n                c+=i[2];\n                ans+=i[2]*n;\n                ans-=r;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']