3408. Design Task Manager
Description
There is a task management system that allows users to manage their tasks, each associated with a priority. The system should efficiently handle adding, modifying, executing, and removing tasks.
Implement the TaskManager class:
- TaskManager(vector<vector<int>>&; tasks)initializes the task manager with a list of user-task-priority triples. Each element in the input list is of the form- [userId, taskId, priority], which adds a task to the specified user with the given priority.
- void add(int userId, int taskId, int priority)adds a task with the specified- taskIdand- priorityto the user with- userId. It is guaranteed that- taskIddoes not exist in the system.
- void edit(int taskId, int newPriority)updates the priority of the existing- taskIdto- newPriority. It is guaranteed that- taskIdexists in the system.
- void rmv(int taskId)removes the task identified by- taskIdfrom the system. It is guaranteed that- taskIdexists in the system.
- int execTop()executes the task with the highest priority across all users. If there are multiple tasks with the same highest priority, execute the one with the highest- taskId. After executing, the- taskIdis removed from the system. Return the- userIdassociated with the executed task. If no tasks are available, return -1.
Note that a user may be assigned multiple tasks.
Example 1:
| 1 | Input: | 
Constraints:
- 1 <= tasks.length <= 10^5
- 0 <= userId <= 10^5
- 0 <= taskId <= 10^5
- 0 <= priority <= 10^9
- 0 <= newPriority <= 10^9
- At most 2 * 10^5calls will be made in total toadd,edit,rmv, andexecTopmethods.
- The input is generated such that taskIdwill be valid.
Hints/Notes
- 2025/01/12
- lazy priority queue
- 0x3Fâs solution(checked)
- Biweekly Contest 147
Solution
Language: C++
| 1 | class TaskManager { |