Codeforces Round 818 (Div. 2) D. Madoka and The Corruption Scheme
6894. Sum of Imbalance Numbers of All Subarrays
The imbalance number of a 0-indexed integer array
arrof lengthnis defined as the number of indices insarr = sorted(arr)such that:
0 <= i < n - 1, andsarr[i+1] - sarr[i] > 1Here,
sorted(arr)is the function that returns the sorted version ofarr.Given a 0-indexed integer array
nums, return the sum of imbalance numbers of all its subarrays.A subarray is a contiguous non-empty sequence of elements within an array.
You are given a 0-indexed integer array
nums. A subarray ofnumsis called continuous if:
- Let
i,i + 1, …,jbe the indices in the subarray. Then, for each pair of indicesi <= i1, i2 <= j,0 <= |nums[i1] - nums[i2]| <= 2.Return the total number of continuous subarrays.
A subarray is a contiguous non-empty sequence of elements within an array.
6916. Prime Pairs With Target Sum
You are given an integer
n. We say that two integersxandyform a prime number pair if:
1 <= x <= y <= nx + y == nxandyare prime numbersReturn the 2D sorted list of prime number pairs
[xi, yi]. The list should be sorted in increasing order ofxi. If there are no prime number pairs at all, return an empty array.Note: A prime number is a natural number greater than
1with only two factors, itself and1.
6909. Longest Even Odd Subarray With Threshold
You are given a 0-indexed integer array
numsand an integerthreshold.Find the length of the longest subarray of
numsstarting at indexland ending at indexr(0 <= l <= r < nums.length)that satisfies the following conditions:
nums[l] % 2 == 0- For all indices
iin the range[l, r - 1],nums[i] % 2 != nums[i + 1] % 2- For all indices
iin the range[l, r],nums[i] <= thresholdReturn an integer denoting the length of the longest such subarray.
Note: A subarray is a contiguous non-empty sequence of elements within an array.