Processing math: 100%
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,…,x appear at least once in S. ### Input - The first line contains two integers n,q. - The second line contains n integers Ai. - 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≤n,q≤2×105. - 1≤Ai≤109. - 1≤x≤109. ### Examples Input: 5311243543 Output: -144