#P1366. Counting Occurrences in Sorted Arrays
Counting Occurrences in Sorted Arrays
Counting Occurrences in Sorted Arrays
Given two sequences\( a \) and \( b \), both sorted in non-decreasing order. It is guaranteed that the sequence \( a \) contains no duplicate numbers. For each number in \( a \), count how many times it appears in \( b \).
Note: The input sequences are provided such that the first line contains two integers \( n \) and \( m \), denoting the lengths of \( a \) and \( b \) respectively. The second line contains \( n \) space-separated integers in sequence \( a \) and the third line contains \( m \) space-separated integers in sequence \( b \). The output should list the count of each number from \( a \) in \( b \) in order, separated by spaces.
inputFormat
The input consists of three lines:
- The first line contains two integers \( n \) and \( m \), the lengths of sequences \( a \) and \( b \) respectively.
- The second line contains \( n \) space-separated integers representing sequence \( a \) (sorted in non-decreasing order and no duplicates).
- The third line contains \( m \) space-separated integers representing sequence \( b \) (sorted in non-decreasing order, may have duplicates).
outputFormat
Output a single line containing \( n \) integers. The \( i^{th} \) integer is the number of times the \( i^{th} \) number in sequence \( a \) appears in sequence \( b \). The numbers should be separated by spaces.
sample
3 6
1 3 5
1 1 3 3 3 7
2 3 0