#C10694. User Watch History Tracker
User Watch History Tracker
User Watch History Tracker
You are given a sequence of operations simulating a user watch history management system. Each operation corresponds to a watch, remove, query or recent command. Maintain the history for each user to track the order in which videos were watched.
For the watch
operation, if the video is already in the user's history, it should be moved to the end. For remove
, remove the video if it exists. For query
, output YES
if the video is present in the user's history, otherwise NO
. For recent
, output the most recent k videos in reverse order (most recent first), separated by a single space. If the user has no videos watched, output No videos watched.
Constraints:
- \( 1 \leq n \leq 10^5 \), where \( n \) is the number of operations.
- Each operation is given in the format described in the Input section.
inputFormat
The first line contains an integer \( n \), the number of operations.
Each of the following \( n \) lines contains an operation in one of the following formats:
watch user_id video_id
remove user_id video_id
query user_id video_id
recent user_id k
All tokens are separated by a single space.
outputFormat
For each query
and recent
operation, output the result on a new line.
- For
query
, outputYES
if the video is in the user's watch history, otherwiseNO
. - For
recent
, output the k most recent video IDs in reverse order (most recent first), separated by a single space. If the user has not watched any videos, output No videos watched.
10
watch user1 vid1
watch user1 vid2
watch user1 vid1
query user1 vid1
query user1 vid2
remove user1 vid1
query user1 vid1
recent user1 1
watch user1 vid3
recent user1 2
YES
YES
NO
vid2
vid3 vid2
</p>