Maximize Count of Distinct Primes After Split
You are given an integer array nums having length n and a 2D integer array queries where queries[i] = [idx, val].
For each query:
- Update
nums[idx] = val. - Choose an integer
kwith1 <= k < nto split the array into the non-empty prefixnums[0..k-1]and suffixnums[k..n-1]such that the sum of the counts of distinct prime values in each part is maximum.
Note: The changes made to the array in one query persist into the next query.
Return an array containing the result for each query, in the order they are given.
Example 1
Input
nums = [2,1,3,1,2], queries = [[1,2],[3,3]]Output
[3,4]After the first query, the best split gives 1 distinct prime in the prefix and 2 in the suffix, and after the second query the best split gives 2 plus 2.
Example 2
Input
nums = [2,1,4], queries = [[0,1]]Output
[0]After the query,
nums contains no prime numbers, so the maximum sum is 0.Constraints
- 2 <= n == nums.length <= 5 * 10^4
- 1 <= queries.length <= 5 * 10^4
- 1 <= nums[i] <= 10^5
- 0 <= queries[i][0] < nums.length
- 1 <= queries[i][1] <= 10^5