← 返回 airbnb 的题目列表Task Management System with Expiring Assignments and Overdue Tracking
类型:online_judge
Implement SimpleTaskManagementSystem, a task-management system with task search, user quotas, expiring assignments, completion, and overdue-assignment history. Operations are executed in call order, and operation timestamps are strictly increasing.
priority and quota are non-negative integers.
timestamp and finish_time are positive integers.
Task IDs are generated sequentially starting with "task_id_1".
Implement:
add_task(timestamp: int, name: str, priority: int) -> str
update_task(timestamp: int, task_id: str, name: str, priority: int) -> bool
get_task(timestamp: int, task_id: str) -> str | None
search_tasks(timestamp: int, name_filter: str, max_results: int) -> list[str]
list_tasks_sorted(timestamp: int, limit: int) -> list[str]
add_user(timestamp: int, user_id: str, quota: int) -> bool
assign_task(timestamp: int, task_id: str, user_id: str, finish_time: int) -> bool
get_user_tasks(timestamp: int, user_id: str) -> list[str]
complete_task(timestamp: int, task_id: str, user_id: str) -> bool
get_overdue_assignments(timestamp: int, user_id: str) -> list[str]
Tasks
add_task creates a task and returns its unique sequential ID. Duplicate (name, priority) pairs are allowed.
update_task updates a task's name and priority and returns whether the task exists. Updating a task must not change its creation order.
get_task returns a compact JSON string in exactly this key order: name, then priority, e.g. {"name":"Task 1","priority":5}. Return None when absent.
search_tasks performs a case-sensitive substring search on task names. Return at most max_results IDs, sorted by descending priority and then ascending creation order. Return [] if max_results <= 0.
list_tasks_sorted uses the same ordering and returns at most limit IDs. Return [] if limit <= 0.
Users and assignments
add_user adds a user with a maximum number of simultaneous active assignments. Return False for duplicate users.
assign_task creates an independent assignment active on [timestamp, finish_time). It fails if the task or user does not exist, or if the user's active unfinished assignment count has reached the quota. The same task may be assigned repeatedly, including repeatedly to the same user.
get_user_tasks returns active, unfinished task IDs for a user at timestamp, ordered by (finish_time, start_time). Return [] for an unknown user.
complete_task completes one active unfinished assignment for (task_id, user_id) and frees quota immediately. If multiple matching active assignments exist, complete the one with the earliest start_time.
get_overdue_assignments returns IDs for assignments whose finish_time <= timestamp and which were never completed. A task ID may appear more than once. Sort by (finish_time, start_time).
Example:
system.add_user(1, "user1", 2) # True
system.add_task(2, "Alpha", 10) # "task_id_1"
system.add_task(3, "Bravo", 15) # "task_id_2"
system.assign_task(4, "task_id_1", "user1", 10) # True
system.assign_task(5, "task_id_2", "user1", 8) # True
system.get_user_tasks(6, "user1") # ["task_id_2", "task_id_1"]
system.complete_task(7, "task_id_2", "user1") # True
system.assign_task(8, "task_id_2", "user1", 12) # True
system.get_overdue_assignments(11, "user1") # ["task_id_1"]
Time limit: 3 seconds. Memory limit: 4 GB.
Example
Input
add_task(1, "Task 1", 5)\nadd_task(2, "Task 1", 5)\nupdate_task(3, "task_id_1", "Updated Task 1", 4)\nget_task(4, "task_id_1")\nupdate_task(5, "task_id_3", "Missing", 1)
Output
"task_id_1"\n"task_id_2"\nTrue\n{"name":"Updated Task 1","priority":4}\nFalse