K-Distinct Subarrays
View as PDF
Submit solution
Points:
100
Time limit:
1.0s
PyPy 3
2.0s
Python 3
2.0s
Memory limit:
500M
Problem type
Given an array of
integers, count how many non-empty subarrays contain at least
distinct values.
Remember that a subarray is a contiguous section of the array.
Input
The first line contains two integers and
.
The second line contains integers
.
Output
Print a single integer: the number of non-empty subarrays that contain at least distinct
values.
Constraints
Example 1
Input
5 3
1 2 1 3 2
Output
5
Explanation
The subarrays with at least distinct values are:
Comments