report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Full sequence - FlandreOJ: Flandre 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 ```
Introduction to Segment Tree and Binary Indexed Tree
Point update, sum query
Point update, minimum query
Range update, sum query
Range update, minimum query
Apple picking
Non-negative subarray
Inversions
K-query
Divisible by 3
Mushroom harvesting
KSS
D-query
Greatest subarray sum
Copying data
Within 1
Within 2
Ladder update
Racing
One time
Subarray XOR
String sorting
Odd query
Full sequence
Topic
Data structure
Rating 2000
Solution (1) Solution