Problems > How Many Times Does X Appear

How Many Times Does X Appear

Difficulty: 1000 3500 ms 128 MB

implementation

Given the array once and then Q queries, print how many times each queried value occurs.

Input: the first line has N and Q; the second line has the array; the next Q lines each have one query value.

Output: Q lines with the frequencies (0 for absent values).

Constraints:

  • 1 ≤ N, Q ≤ 105
  • |values| ≤ 109

Sample Tests

Input 1
5 3
1 2 2 3 2
2
4
1
Output 1
3
0
1
Input 2
1 1
7
7
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.