2552. Count Increasing Quadruplets Hard

@problem@discussion
#Array#Dynamic Programming#Binary Indexed Tree#Enumeration#Prefix Sum



1/**
2 * [2552] Count Increasing Quadruplets
3 *
4 * Given a 0-indexed integer array nums of size n containing all numbers from 1 to n, return the number of increasing quadruplets.
5 * A quadruplet (i, j, k, l) is increasing if:
6 * 
7 * 	0 <= i < j < k < l < n, and
8 * 	nums[i] < nums[k] < nums[j] < nums[l].
9 * 
10 *  
11 * <strong class="example">Example 1:
12 * 
13 * Input: nums = [1,3,2,4,5]
14 * Output: 2
15 * Explanation: 
16 * - When i = 0, j = 1, k = 2, and l = 3, nums[i] < nums[k] < nums[j] < nums[l].
17 * - When i = 0, j = 1, k = 2, and l = 4, nums[i] < nums[k] < nums[j] < nums[l]. 
18 * There are no other quadruplets, so we return 2.
19 * 
20 * <strong class="example">Example 2:
21 * 
22 * Input: nums = [1,2,3,4]
23 * Output: 0
24 * Explanation: There exists only one quadruplet with i = 0, j = 1, k = 2, l = 3, but since nums[j] < nums[k], we return 0.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	4 <= nums.length <= 4000
30 * 	1 <= nums[i] <= nums.length
31 * 	All the integers of nums are unique. nums is a permutation.
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/count-increasing-quadruplets/
37// discuss: https://leetcode.com/problems/count-increasing-quadruplets/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn count_quadruplets(nums: Vec<i32>) -> i64 {
43        
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_2552() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.