Problem list
Log in
#r03117 · Online Judge > GoldOJ

First Occurrence Position

Silver III 2.0 s 1024 MB

A sorted array of $N$ integers (duplicates allowed) is given, then $Q$ queries. For each value $K$ print the 1-based position of its first occurrence, or -1 if $K$ is not present.

Input

Line 1: $N$ $Q$. Line 2: $N$ sorted integers. Next $Q$ lines: a value each.

Output

Print the first-occurrence position (or -1) for each query.

Example 1

Input
10 4
1 2 2 2 5 5 7 9 9 10
2
5
9
3
Output
2
5
8
-1

Example 2

Input
7 5
-5 -5 -1 0 0 0 8
-5
0
8
7
-10
Output
1
4
7
-1
-1
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code