From 9a82ec82f7d21998bc2ca4f3dfb60136930f18a8 Mon Sep 17 00:00:00 2001 From: li_chx Date: Wed, 10 Dec 2025 15:49:39 +0800 Subject: [PATCH] =?UTF-8?q?3583.=20=E7=BB=9F=E8=AE=A1=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E4=B8=89=E5=85=83=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index d3092f7..ec2b5e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,30 @@ +use std::collections::HashMap; + struct Solution; mod arr; impl Solution { - pub fn count_permutations(complexity: Vec) -> i32 { - let md= 1e9 as i64 + 7; - let mut ans = 1_i64; - for i in 1..complexity.len() { - if complexity[i] <= complexity[0] { - return 0; + pub fn special_triplets(nums: Vec) -> i32 { + let mut map: HashMap = HashMap::new(); + let mut map2: HashMap = HashMap::new(); + let md = 1e9 as i64 + 7; + let mut ans = 0_i64; + nums.iter().for_each(|x| { + map.insert(*x, map.get(&x).copied().unwrap_or(0) + 1); + }); + map2.insert(nums[0], 1); + for i in 1..nums.len() - 1 { + let mp2d = map2.get(&(nums[i] * 2)).copied().unwrap_or(0) as i64; + let mut mp1d = map.get(&(nums[i] * 2)).copied().unwrap_or(0) as i64 - mp2d; + if nums[i] == nums[i] * 2 { + mp1d -= 1; } - ans = (ans * i as i64) % md; + ans = (ans + mp1d * mp2d) % md; + map2.insert(nums[i], map2.get(&nums[i]).copied().unwrap_or(0) + 1); } ans as i32 } } fn main() { - let result = Solution::count_permutations(vec![1, 3, 3, 4, 4, 4]); + let result = Solution::special_triplets(vec![0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]); println!("{:?}", result); }