Binary search 2 - MarisaOJ: Marisa Online Judge

Binary search 2

Time limit: 1000 ms
Memory limit: 256 MB
You are given: - An integer non-decreasing array $A$ of $n$ integers. - $q$ queries, each is an integer $x$, find the smallest $i$ that $A_i = x$. ### Input - The first line contains 2 integer $n, q$. - The second line contains $n$ space-separated integers $A_i$. - The next $q$ lines, each contains an single integer $x$, a query. ### Output - Print $q$ lines, $i^{th}$ line is the answer to query $i$. Print `-1` if $x$ cannot be found. ### Constraints - $1 \le n, q \le 10^{5}$. - $1 \le A_i \le 10^9$. ### Example Input: ``` 5 3 1 2 3 3 9 1 9 3 ``` Output: ``` 1 5 3 ```