#C983. Airstream Movie Query
Airstream Movie Query
Airstream Movie Query
Airstream Inc. has developed a streaming service that maintains a record of movies watched by its users. Each user has their own watch history. The service supports two types of operations:
watch u m
: Indicates that user u watched movie m.query u start end
: Reports the number of unique movies that user u watched from the start-th watch to the end-th watch in their personal history. The indices are 1-indexed. If theend
index exceeds the number of movies watched so far by the user, consider all recorded watches from thestart
-th onward.
Note: The operations are processed in order. The query
operation extracts a subarray from the user's watch history (from index start-1 to end, using Python slice semantics) and computes the count of distinct movie IDs in that subarray.
Example:
Input operations: watch 1 101 watch 1 102 watch 2 101 watch 1 102 query 1 1 3 watch 1 103 query 1 2 5</p>For user 1, the watch history becomes [101, 102, 102, 103]. Query 1: The subarray from 1 to 3 is [101, 102, 102], which has 2 unique movies. Query 2: The subarray from 2 to 5 is [102, 102, 103] (if end exceeds the length, take until the end), which has 2 unique movies.
Other test cases may vary. (See Input/Output descriptions below.)
inputFormat
The first line contains an integer n
representing the total number of operations. The following n
lines each contain an operation in one of the following formats:
watch u m
— useru
watches moviem
(both are positive integers).query u start end
— query the number of unique movies that useru
watched in the subarray of their watch history from thestart
-th to theend
-th watch (1-indexed).
outputFormat
For each query
operation, output a single integer on a new line representing the number of unique movies in the specified segment of the user's watch history.
6
watch 1 101
watch 1 102
watch 1 103
query 1 1 3
query 1 1 2
query 1 2 3
3
2
2
</p>