Easy to Understand || Reverse One Pass || HashSet
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nuse std::collections::HashSet;\n\nimpl Solution {\n    pub fn matrix_sum_queries(n: i32, queries: Vec<Vec<i32>>) -> i64 {\n        let (mut rows, mut cols) = (HashSet::new(), HashSet::new());\n        let n = n as i64;\n        let mut ans = 0;\n        \n        for q in queries.iter().rev() {\n            if q[0] == 0 {\n                if !rows.insert(q[1]) { continue };\n                ans += (n - cols.len() as i64) * q[2] as i64;\n            } else {\n                if !cols.insert(q[1]) { continue };\n                ans += (n - rows.len() as i64) * q[2] as i64;\n            }\n        }\n        \n        ans\n    }\n}\n```
['Rust']