Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Try using a segment tree to store the maximal alternating groups.
Store the sizes of these maximal alternating groups in another data structure.
Solve with full IDE support and test cases
Find the count of the alternating groups of size <code>k</code> with having the count of maximal alternating groups with size greater than or equal to <code>k</code> and the sum of their sizes.