Full sequence - MarisaOJ: Marisa Online Judge

Full sequence

Time limit: 1000 ms
Memory limit: 256 MB
Given an array $A$ of $n$ integers. Your task is to answer $q$ queries. Each query consists of a number $x$, requiring you to find the length of the shortest contiguous subarray $S$ of $A$ such that all values in ${1, 2, \dots, x}$ appear at least once in $S$. ### Input - The first line contains two integers $n, q$. - The second line contains $n$ integers $A_i$. - The next $q$ lines each contain one integer $x$, representing a query. ### Output - For each query, print the length of the shortest subarray that satisfies the condition. Print $-1$ if no such subarray exists. ### Constraints - $1 \le n, q \le 2 \times 10^5$. - $1 \le A_i \le 10^9$. - $1 \le x \le 10^9$. ### Examples Input: ``` 5 3 1 1 2 4 3 5 4 3 ``` Output: ``` -1 4 4 ```