Binary search - MarisaOJ: Marisa Online Judge

Binary search

Time limit: 1000 ms
Memory limit: 256 MB
Given a sorted array $A$ consisting of $n$ distinct integers in ascending order. There are $q$ queries, each query is an integer $x$. Determine the position of this value in the array $A$. ### Input - The first line contains two integers $n$ and $q$. - The second line contains $n$ integers $A_i$ in ascending order. - The next $q$ lines each contain an integer $x$, a query. ### Output - For each query, print the position of the given integer in the array $A$. Ensure that there exists a valid answer. ### Constraints - $1 \le n,q \le 10^5$. - $1 \le A_i, x \le 10^9$. ### Example Input: ``` 5 3 1 4 6 8 10 4 10 1 ``` Output: ``` 2 5 1 ```