Under construction

Still being built. Things may change

Mode and Queries

Time limit3sMemory limit256 MB

Summary
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.
Level

Medium6 of 10

Topics
Sorting, Array, Hash map
Solved
No attempts yet

Problem

You are given an integer sequence AA of length NN and a constant KK. For each of the QQ queries below, print the answer.

  • ll rr: Among the contiguous subsequences that use only the elements Al,Al+1,…,ArA_l, A_{l+1}, \ldots, A_r, output the minimum length of one in which some value appears at least KK times. If no such subsequence exists, output −1-1.

Input

The first line contains NN, KK, and QQ in this order. (1≤N,K,Q≤200 0001 \le N, K, Q \le 200\,000)

The second line contains the NN elements of AA in order. (1≤Ai≤N1 \le A_i \le N)

Each of the next QQ lines contains ll and rr. (1≤l≤r≤N1 \le l \le r \le N)

Output

Print QQ lines. The ii-th line contains the answer to the ii-th query.

Hint

A sequence BB is a contiguous subsequence of AA if there exist an integer MM with 1≤M≤N1 \le M \le N and an integer ii with 1≤i+M<N1 \le i+M < N such that the jj-th element of BB equals the (i+j−1)(i+j-1)-th element of AA for every integer jj with 1≤j≤M1 \le j \le M.

Examples1

  1. Example 1

    Input
    5 2 6
    1 2 1 2 3
    2 3
    1 2
    3 5
    1 5
    1 4
    1 5
    
    Expected output
    -1
    -1
    -1
    3
    3
    3