Perfect Ribbon (APCS 2019-06 Expert)
2.0s 256MA ribbon consists of \(n\) colored blocks and uses exactly \(m\) distinct colors. A consecutive segment of length \(m\) is perfect if it contains each color exactly once. Count perfect segments, counting different starting positions separately.
Input Format
The first line contains \(m,n\). The second line lists the \(n\) color identifiers in order.
Output Format
Print the number of perfect segments.
Constraints
\(2\le m\le n\le200000\). Color identifiers are integers from \(0\) to \(10^9\), and exactly \(m\) distinct identifiers occur.
Sample Input
4 10
1 4 1 7 6 4 4 6 1 7
Sample Output
3
Source
APCS 2019-06 public archive version: tcirc:d036。
Log in to write and submit code.
Log in