c++
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 {
// nlog(n) initialization, rest log(n)
    struct task {
        int userid;
        int taskid;
        int priority;
    };
    struct task_cmp {
        bool operator()(const task& lhs, const task& rhs) const {
            if (lhs.priority == rhs.priority) {
                return lhs.taskid < rhs.taskid;
            }
            return lhs.priority < rhs.priority;
        }
    };
public:
    TaskManager(vector<vector<int>>& tasks) {
        for (const auto& t : tasks) {
            auto p = task_set.insert({t[0], t[1], t[2]});
            taskid_prio[t[1]] = {t[2], p.first};
        }    
    }
    
    void add(int userId, int taskId, int priority) {
        auto p = task_set.insert({userId, taskId, priority});
        taskid_prio[taskId] = {priority, p.first};
    }
    
    void edit(int taskId, int newPriority) {
        auto old_iter = taskid_prio.find(taskId);
        const int userid = old_iter->second.second->userid;

        task_set.erase(old_iter->second.second);

        auto new_iter = task_set.insert({userid, taskId, newPriority});

        taskid_prio[taskId] = {newPriority, new_iter.first};
    }
    
    void rmv(int taskId) {
        auto it = taskid_prio.find(taskId);        
        task_set.erase(it->second.second);
        taskid_prio.erase(taskId);
    }
    
    int execTop() {
        if (task_set.empty()) {
            return -1;
        }

        const auto it = std::prev(task_set.end());
        const int userid = it->userid;

        const int taskid = it->taskid;
        taskid_prio.erase(taskid);
        task_set.erase(it);

        return userid;
    }
private:
    std::set<task, task_cmp> task_set;
    using task_set_iter = std::set<task, task_cmp>::iterator;
    std::unordered_map<int, std::pair<int, task_set_iter>> taskid_prio;

};

/**
 * 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++']