#C7033. Uniform Event Diversity in Subarrays

    ID: 50860 Type: Default 1000ms 256MiB

Uniform Event Diversity in Subarrays

Uniform Event Diversity in Subarrays

Given an array of integers representing different types of events, your task is to determine whether each continuous subarray of length \(K\) has an identical number of distinct events. In other words, for every contiguous block (or window) of \(K\) elements in the array, the number of unique events must be the same.

More formally, let \(arr\) be an array of \(N\) integers and let \(K\) be a positive integer such that \(K \leq N\). Define \(S_i = \{ arr[i], arr[i+1], \ldots, arr[i+K-1] \}\) for \(1 \leq i \leq N-K+1\). The goal is to check if \(|S_1| = |S_2| = \cdots = |S_{N-K+1}|\). If they are all equal, output YES; otherwise, output NO.

Note: Although the input includes a parameter \(M\) denoting the number of different types of events globally, it is not necessarily used in the computation.

Example:

Input:
5 3 3
1 2 2 1 3

Output: NO

</p>

In the above example, the subarrays of length \(3\) are [1, 2, 2], [2, 2, 1], and [2, 1, 3]. Their counts of distinct elements are 2, 2, and 3 respectively, so the answer is NO.

inputFormat

The input is read from stdin and consists of two lines:

  1. The first line contains three space-separated integers: \(N\) (the number of events), \(M\) (the number of different event types, not necessarily used), and \(K\) (the subarray length to check).
  2. The second line contains \(N\) space-separated integers representing the event identifiers.

outputFormat

The output is a single line printed to stdout containing either YES if every contiguous subarray of length \(K\) has the same number of distinct elements, or NO otherwise.

## sample
5 3 3
1 2 2 1 3
NO