Processing math: 100%
Binary search 2 - MarisaOJ: Marisa Online Judge
You are given:
- An integer non-decreasing array A of n integers.
- q queries, each is an integer x, find the smallest i that Ai=x.
- The first line contains 2 integer n,q.
- The second line contains n space-separated integers Ai.
- The next q lines, each contains an single integer x, a query.
Output
- Print q lines, ith line is the answer to query i. Print
-1
if x cannot be found.
Constraints
- 1≤n,q≤105.
- 1≤Ai≤109.
Example
Input:
5 3
1 2 3 3 9
1
9
3
Output:
1
5
3
Topic
Binary search
Rating
800
Solution (0)
Solution