Mode and Queries
Time limit3sMemory limit256 MB
For each query range [l, r], find the shortest contiguous subarray inside it where some value appears at least K times, or -1 if none exists.
Problem
You are given an integer sequence of length and a constant . For each of the queries below, print the answer.
- : Among the contiguous subsequences that use only the elements , output the minimum length of one in which some value appears at least times. If no such subsequence exists, output .
Input
The first line contains , , and in this order. ()
The second line contains the elements of in order. ()
Each of the next lines contains and . ()
Output
Print lines. The -th line contains the answer to the -th query.
Hint
A sequence is a contiguous subsequence of if there exist an integer with and an integer with such that the -th element of equals the -th element of for every integer with .