Redaksiya
Let's consider the structure , where contains the number of villages with the name . We'll read the villages in Karabakh and build the map . Then, for each village , we'll print the number of times occurs.
Algorithm realization
Declare the data structure .
map<int, int> m;
Read the input data. Store the villages of Karabakh in the map .
scanf("%d %d", &n, &q); for (i = 0; i < n; i++) { scanf("%d", &x); m[x]++; }
Process queries. For each village , print the number of times occurs.
for (i = 0; i < q; i++) { scanf("%d", &x); printf("%d\n", m[x]); }
Python realization
Read the input data.
n, q = map(int, input().split()) lst = list(map(int, input().split()))
Declare the vocabulary .
m = {}
Store the information about the villages of Karabakh in the vocabulary .
for x in lst: if x in m: m[x] += 1 else: m[x] = 1
Process queries. For each village , print the number of times occurs. If the village is not found in the vocabulary, print .
for _ in range(q): x = int(input()) print(m.get(x, 0))