← 返回 netflix 的题目列表Bucket Users by Movie Completion Percentage from an Event Stream
类型:online_judge
Given an event stream of users watching movies, each event contains the completion percentage for a user and a movie.
Bucket users per movie by completion thresholds (e.g., 30%, 50%, 80%) and output, for each movie, how many users fall into each bucket.
Requirements:
Input:
Line 1: three integer thresholds t1 t2 t3 (e.g., 30 50 80) with 0 <= t1 < t2 < t3 <= 100.
Line 2: integer n, number of events.
Next n lines: user_id movie_id pct, where pct is an integer in [0,100].
Multiple events may exist for the same (user_id, movie_id); use the maximum pct as the final completion for that user and movie.
Bucketing:
bucket0: pct < t1
bucket1: t1 <= pct < t2
bucket2: t2 <= pct < t3
bucket3: pct >= t3
Output: for each movie_id (ascending), print counts of users in each bucket.
Output line format: movie_id c0 c1 c2 c3
Constraints:
1 <= n <= 2e5
user_id, movie_id are non-negative integers up to 1e9
Target complexity: ~O(n) or O(n log n) time, space proportional to the number of distinct (user_id, movie_id) pairs.
Example
Input
30 50 80
8
1 10 20
1 10 35
2 10 80
3 10 79
1 11 90
2 11 10
2 11 60
2 11 70
Output
10 1 1 1 1
11 1 0 1 1