← 返回 apple 的题目列表Design Task Manager
类型:online_judge
Design a TaskManager. Each task is represented by [userId, taskId, priority], and every taskId is unique.
Implement the following operations:
TaskManager(tasks): Initialize the manager with initial tasks.
add(userId, taskId, priority): Add a new task. The taskId is guaranteed not to exist.
edit(taskId, newPriority): Change the priority of an existing task.
rmv(taskId): Remove an existing task.
execTop(): Execute and remove the currently highest-priority task, returning its userId.
If multiple tasks have the same priority, execute the one with the larger taskId.
Return -1 if no task exists.
Example
TaskManager([[1,101,10],[2,102,20]])
execTop() -> 2
add(3,103,15)
edit(101,30)
execTop() -> 1
execTop() -> 3
execTop() -> -1
Constraints
The number of initial tasks and total operations are at most 10^5.
Each operation should run in O(log n) amortized time or better.
Example
Input
2
1 101 10
2 102 20
6
execTop
add 3 103 15
edit 101 30
execTop
execTop
execTop
Output
2
1
3
-1