20240910 finished.

This commit is contained in:
jackfiled 2024-09-10 11:50:53 +08:00
parent f4dcf1a23d
commit d03c1058c1
2 changed files with 48 additions and 1 deletions

View File

@ -230,4 +230,5 @@ mod p3174_clear_digits;
mod p3176_find_the_maximum_length_of_a_good_subsequence_i; mod p3176_find_the_maximum_length_of_a_good_subsequence_i;
mod p3177_find_the_maximum_length_of_a_good_subsequence_ii; mod p3177_find_the_maximum_length_of_a_good_subsequence_ii;
mod p977_squares_of_a_sorted_array; mod p977_squares_of_a_sorted_array;
mod p2181_merge_nodes_in_between_zeros; mod p2181_merge_nodes_in_between_zeros;
mod p2552_count_increasing_quadruplets;

View File

@ -0,0 +1,46 @@
/**
* [2552] Count Increasing Quadruplets
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn count_quadruplets(nums: Vec<i32>) -> i64 {
let nums: Vec<usize> = nums.iter().map(|x| *x as usize).collect();
let n = nums.len();
let mut pre = vec![0;n + 1];
let mut result = 0;
for j in 0..n {
let mut suffix = 0;
for k in (j + 1..n).rev() {
if nums[j] > nums[k] {
result += pre[nums[k]] * suffix;
} else {
suffix += 1;
}
}
for i in nums[j] + 1..=n {
pre[i] += 1;
}
}
result
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_2552() {
assert_eq!(2, Solution::count_quadruplets(vec![1,3,2,4,5]));
}
}