Implementation map+set TC-O(log n)
Complexity
Time complexity: O(log n)

Space complexity: O(N)
Code


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

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

# Code
```cpp []
class TaskManager {
public:
    vector<vector<int>> task1;
    map<int,int> m;
    set<pair<int,int>> s;
    map<int,int> m1;
    TaskManager(vector<vector<int>>& tasks) {
        this->task1=tasks;
        for(auto i:task1){
            int user=i[0];
            int task=i[1];
            int priority1=i[2];
            m[task]=priority1;
            m1[task]=user;
            s.insert({priority1,task});
        }
    }
    
    void add(int userId, int taskId, int priority) {
        m[taskId]=priority;
         m1[taskId]=userId;
         s.insert({priority,taskId});
    }
    
    void edit(int taskId, int newPriority) {
        int priority=m[taskId];
        m[taskId]=newPriority;
        s.erase({priority,taskId});
        s.insert({newPriority,taskId});
    }
    
    void rmv(int taskId) {
        int priority=m[taskId];
        m.erase(taskId);
        m1.erase(taskId);
        s.erase({priority,taskId});
    }
    
    int execTop() {
        if(s.size()!=0){
            auto it=--s.end();
            int p=it->first;
            int t=it->second;
            int ans=m1[t];
            m.erase(t);
            m1.erase(t);
            s.erase(it);
            return ans;
        }
        return -1;
    }
};

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