← 返回 bloomberg 的题目列表Bucket Values Into Boundary Ranges
类型:online_judge
Given a sorted boundary array boundaries (length m) and an array arr, bucket each value in arr into the interval formed by adjacent boundaries.
For each x, find the unique i such that:
boundaries[i] <= x < boundaries[i+1]
Then x belongs to bucket i. Output the counts for all buckets.
If x < boundaries[0] or x >= boundaries[m-1], ignore it.
Input (stdin)
Line 1: two integers m n. Line 2: m integers, strictly increasing boundaries. Line 3: n integers, the array arr.
Output (stdout)
Print m-1 integers: counts of each bucket.
Constraints
2 <= m <= 2*10^5
0 <= n <= 2*10^5
boundaries strictly increasing
arr[i] is a 32-bit signed integer
Expected complexity: O(n log m) or better
Example
Input
4 7
0 10 20 30
-1 0 5 10 19 20 100
Output
2 2 1