c++(314ms) tree & hash
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- 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:
  set<tuple<int,int,int>> st;
  unordered_map<int, pair<int,int>> mp;

  TaskManager(vector<vector<int>>& tasks) {
    for(auto &t: tasks) st.insert({t[2], t[1], t[0]}), mp[t[1]] = {t[0], t[2]};      
  }
    
  void add(int userId, int taskId, int priority) {
    st.insert({priority, taskId, userId});
    mp[taskId] = {userId, priority};    
  }
    
  void edit(int taskId, int newPriority) {
    auto [uId, p] = mp[taskId];
    mp[taskId] = {uId, newPriority};
    st.erase({p, taskId, uId});
    st.insert({newPriority, taskId, uId});      
  }
    
  void rmv(int taskId) {
    auto [uId, p] = mp[taskId];
    mp.erase(taskId);
    st.erase({p, taskId, uId});    
  }
    
  int execTop() {
    if(st.size() == 0) return -1;

    auto [p, tId, uId] = *st.rbegin();
    st.erase(*st.rbegin());
    mp.erase(tId);

    return uId;     
  }
};

/**
 * Your TaskManager object will be instantiated and called as such:
 * TaskManager* obj = new TaskManager(tasks);
 * obj->add(userId,taskId,priority);
 * obj->edit(taskId,newPriority);
 * obj->rmv(taskId);
 * int param_4 = obj->execTop();
 */
```
['C++']