have a card deck of n cards, numbered through and through, I. e. the top card has list 1 and base card — file n. Each card has its tone: the I-th card has shading artificial intelligence. You should handle q inquiries. The j-th inquiry is depicted by integer tj. For each inquiry you ought to:
Correct answer will be upvoted else downvoted. Computer science.
You have a card deck of n cards, numbered through and through, I. e. the top card has list 1 and base card — file n. Each card has its tone: the I-th card has shading
You should handle q inquiries. The j-th inquiry is depicted by integer tj. For each inquiry you ought to:
track down the most elevated card in the deck with shading tj, I. e. the card with least list;
print the situation of the card you found;
assume the card and position it on top of the deck.
Input
The primary line contains two integers n and q (2≤n≤3⋅105; 1≤q≤3⋅105) — the number of cards in the deck and the number of questions.
The subsequent line contains n integers a1,a2,… ,an (1≤ai≤50) — the shades of cards.
The third line contains q integers t1,t2,… ,tq (1≤tj≤50) — the inquiry tones. It's reliable that inquiries ask just shadings that are available in the deck.
Output
Print q integers — the responses for each inquiry
Step by step
Solved in 3 steps with 1 images