P2249 [Shenji 13. Example 1] Search

Description

Input $n$ non-negative integers $a_1, a_2, \dots, a_n$ that are non-decreasing (meaning each later number is not smaller than the previous one), and each does not exceed $10^9$. Then perform $m$ queries. For each query, an integer $q$ is given. You need to output the index of the first occurrence of this number in the sequence. If it is not found, output $-1$.

Input Format

The first line contains two integers $n$ and $m$, representing the number of integers and the number of queries. The second line contains $n$ integers, representing the numbers to be queried. The third line contains $m$ integers, representing the query numbers. The indices start from $1$.

Output Format

Output one line containing $m$ integers separated by spaces, representing the answers.

Explanation/Hint

Constraints: $1 \leq n \leq 10^6$, $0 \leq a_i, q \leq 10^9$, $1 \leq m \leq 10^5$. The input and output size of this problem is large. Please use fast I/O methods. Translated by ChatGPT 5