C++ | Using Two Sets
\n\n# Code\n\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n        long long sum = 0;\n        unordered_se
\n\n# Code\n```\nclass Solution {\npublic:\n    long long matrixSumQueries(int n, vector<vector<int>>& queries) {\n        long long sum = 0;\n        unordered_set<int> row, col;\n        for (int i = queries.size() - 1; i >= 0; i--){\n            if(queries[i][0]){\n                if(col.find(queries[i][1]) == col.end()){\n                    col.insert(queries[i][1]);\n                    sum += (n - row.size()) * queries[i][2];\n                }\n            }\n            else{\n                if(row.find(queries[i][1]) == row.end()){\n                    row.insert(queries[i][1]);\n                    sum += (n - col.size()) * queries[i][2];\n                }\n            }\n        }\n        return sum;\n    }\n};\n```
['C++']