-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3408.py
More file actions
40 lines (32 loc) · 1.32 KB
/
3408.py
File metadata and controls
40 lines (32 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class TaskManager:
def __init__(self, tasks: List[List[int]]):
self.di = {}
self.sl = SortedList()
for t in tasks:
self.add(*t)
def add(self, userId: int, taskId: int, priority: int) -> None:
self.di[taskId] = (userId, priority)
self.sl.add((-priority, -taskId))
def edit(self, taskId: int, newPriority: int) -> None:
userId, priority = self.di[taskId]
self.sl.remove((-priority, -taskId))
self.di.[taskId] = (userId, newPriority)
self.sl.add((-newPriority, -taskId))
def rmv(self, taskId: int) -> None:
userID, priority = self.di[taskId]
del self.di[taskId]
self.sl.remove((-priority, -taskId))
def execTop(self) -> int:
if not self.sl:
return -1
priority, taskId = self.sl.pop(0)
taskId = -taskId
userId, _ = self.di[taskId]
del self.di[taskId]
return userId
# Your TaskManager object will be instantiated and called as such:
# obj = TaskManager(tasks)
# obj.add(userId,taskId,priority)
# obj.edit(taskId,newPriority)
# obj.rmv(taskId)
# param_4 = obj.execTop()