3569. Maximize Count of Distinct Primes After Split Hard

@problem@discussion
#Array#Math#Segment Tree#Number Theory



1/**
2 * [3569] Maximize Count of Distinct Primes After Split
3 *
4 * You are given an integer array nums having length n and a 2D integer array queries where queries[i] = [idx, val].
5 * For each query:
6 * <ol>
7 * 	Update nums[idx] = val.
8 * 	Choose an integer k with 1 <= k < n to split the array into the non-empty prefix nums[0..k-1] and suffix nums[k..n-1] such that the sum of the counts of distinct <span data-keyword="prime-number">prime</span> values in each part is maximum.
9 * </ol>
10 * <strong data-end="513" data-start="504">Note: The changes made to the array in one query persist into the next query.
11 * Return an array containing the result for each query, in the order they are given.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [2,1,3,1,2], queries = [[1,2],[3,3]]</span>
16 * Output: <span class="example-io">[3,4]</span>
17 * Explanation:
18 * 
19 * 	Initially nums = [2, 1, 3, 1, 2].
20 * 	After 1^st query, nums = [2, 2, 3, 1, 2]. Split nums into [2] and [2, 3, 1, 2]. [2] consists of 1 distinct prime and [2, 3, 1, 2] consists of 2 distinct primes. Hence, the answer for this query is 1 + 2 = 3.
21 * 	After 2^nd query, nums = [2, 2, 3, 3, 2]. Split nums into [2, 2, 3] and [3, 2] with an answer of 2 + 2 = 4.
22 * 	The output is [3, 4].
23 * </div>
24 * <strong class="example">Example 2:
25 * <div class="example-block">
26 * Input: <span class="example-io">nums = [2,1,4], queries = [[0,1]]</span>
27 * Output: <span class="example-io">[0]</span>
28 * Explanation:
29 * 
30 * 	Initially nums = [2, 1, 4].
31 * 	After 1^st query, nums = [1, 1, 4]. There are no prime numbers in nums, hence the answer for this query is 0.
32 * 	The output is [0].
33 * </div>
34 *  
35 * Constraints:
36 * 
37 * 	2 <= n == nums.length <= 5 * 10^4
38 * 	1 <= queries.length <= 5 * 10^4
39 * 	1 <= nums[i] <= 10^5
40 * 	0 <= queries[i][0] < nums.length
41 * 	1 <= queries[i][1] <= 10^5
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/maximize-count-of-distinct-primes-after-split/
47// discuss: https://leetcode.com/problems/maximize-count-of-distinct-primes-after-split/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn maximum_count(nums: Vec<i32>, queries: Vec<Vec<i32>>) -> Vec<i32> {
53        vec![]
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_3569() {
65    }
66}
67

Back
© 2026 bowen.ge All Rights Reserved.