#P2249. First Occurrence Finder in a Sorted Sequence
First Occurrence Finder in a Sorted Sequence
First Occurrence Finder in a Sorted Sequence
Given a non-decreasing sequence of \(n\) non-negative integers (each not exceeding \(10^9\)), and \(m\) queries, your task is to find for each query the first occurrence (1-indexed) of the integer \(q\) in the sequence. If \(q\) is not present, output \(-1\).
inputFormat
The first line contains two integers \(n\) and \(m\). The second line contains \(n\) space-separated non-negative integers in non-decreasing order. This is followed by \(m\) lines, each containing a single integer \(q\), representing a query.
outputFormat
For each query, output the first occurrence (1-indexed) of \(q\) in the sequence. If \(q\) is not found, print \(-1\).
sample
5 3
1 2 2 4 5
2
3
5
2
-1
5
</p>