Map and Set
IntuitionUse one map to store priority and userId for each taskId.Since we want the highest priority, use another map to store priority and corresponding taskId
# Intuition
Use one map to store priority and userId for each taskId.

Since we want the highest priority, use another map to store priority and corresponding taskId(s), also for same priority we have to get highest taskId, so we store taskIds in a ordered set.


# edit 
we can get the current priority of taskId by curr_priority = taskMap[taskId][0]

Now since our priority is being updated, we have to erase taskId from curr_priority in priorityMap and insert in newPriority, and similarly update the taskMap

# rmv
we can get the current priority of taskId by curr_priority = taskMap[taskId][0]

We will erase taskId from curr_priority in priorityMap, and similarly erase the taskId from the taskMap

# execTop
For the highest priority, we can get the last priority in the map by
auto high_p = --p.end() => this will give {highestPriority, tasks_set}

Now, to get the highest taskId, we can get by *tasks_set.rbegin()

Now we have tasksId, so userId = tasksMap[tasksId][1]
Remove the taskId and return the userId

<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class TaskManager {
public:
    map<int, set<int>> p; // priority => task_ids
    map<int, vector<int>> t; // taskId => {priority, userId}
    
    TaskManager(vector<vector<int>>& tasks) {
        for (const auto& task : tasks) {
            int userId = task[0];
            int taskId = task[1];
            int priority = task[2];
            add(userId, taskId, priority);
        }
    }
    
    void add(int userId, int taskId, int priority) {
        p[priority].insert(taskId);
        t[taskId] = {priority, userId};
    }
    
    void edit(int taskId, int newPriority) {
        if (t.find(taskId) == t.end()) return;
        
        int curr_p = t[taskId][0];
        p[curr_p].erase(taskId);
        if (p[curr_p].empty()) p.erase(curr_p);
        
        p[newPriority].insert(taskId);
        t[taskId][0] = newPriority;
    }
    
    void rmv(int taskId) {
        if (t.find(taskId) == t.end()) return;
        
        int curr_p = t[taskId][0];
        p[curr_p].erase(taskId);
        if (p[curr_p].empty()) p.erase(curr_p);
        
        t.erase(taskId);
    }
    
    int execTop() {
        if (p.empty()) return -1;
        
        auto high_p = --p.end();
        auto& ts = high_p->second;
        int taskId = *ts.rbegin();

        int userId = t[taskId][1];
        rmv(taskId);
        return userId;
    }
};

```
['Ordered Map', 'Ordered Set', 'C++']