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 a of n integers, count how many non-empty subarrays contain at least k distinct values.

Remember that a subarray is a contiguous section of the array.

Input

The first line contains two integers n and k.

The second line contains n integers a_1, a_2, \dots, a_n.

Output

Print a single integer: the number of non-empty subarrays that contain at least k distinct values.

Constraints

  • 1 \le k \le n \le 2 \cdot 10^5
  • -10^9 \le a_i \le 10^9

Example 1

Input
5 3
1 2 1 3 2
Output
5
Explanation

The subarrays with at least 3 distinct values are:

  • [1, 2, 1, 3]
  • [1, 2, 1, 3, 2]
  • [2, 1, 3]
  • [2, 1, 3, 2]
  • [1, 3, 2]

Comments

There are no comments at the moment.