#K75107. Count Unique Subsequences
Count Unique Subsequences
Count Unique Subsequences
Given a sequence of integers, your task is to count the number of unique subsequences of length \(k\) in which all elements are distinct. A subsequence is obtained by choosing \(k\) elements from the sequence while maintaining their original order. Two subsequences are considered the same if they consist of the same sequence of numbers.
Formally, you are given a sequence \(a_1, a_2, \dots, a_n\) and an integer \(k\). You must count the number of distinct subsequences \((a_{i_1}, a_{i_2}, \dots, a_{i_k})\) (with \(1 \leq i_1 < i_2 < \cdots < i_k \leq n\)) such that \(a_{i_1}, a_{i_2}, \dots, a_{i_k}\) are all unique.
Constraints:
- \(1 \leq k \leq n \leq 200000\)
- \(1 \leq a_i \leq 200000\)
Note: Although the constraints allow large inputs, the intended solutions are expected to work correctly on small test cases.
inputFormat
The input consists of two lines:
- The first line contains two integers \(n\) and \(k\), representing the length of the sequence and the length of the subsequence, respectively.
- The second line contains \(n\) space-separated integers, which are the elements of the sequence.
outputFormat
Output a single integer: the number of unique subsequences of length \(k\) in which all elements are distinct.
## sample5 3
1 2 2 3 4
4
</p>