C++ 73 ms
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:
    TaskManager(const vector<vector<int>>& tasks) {
        enum {USER_ID, TASK_ID, PRIORITY};
        for(const auto& curr : tasks) {
            if(size(users_) <= curr[TASK_ID])
                users_.resize(curr[TASK_ID] + 1);
            tasks_.push({curr[TASK_ID], curr[PRIORITY]});
            users_[curr[TASK_ID]] = {curr[USER_ID], curr[PRIORITY]};
        }
    }
    
    void add(int userId, int taskId, int priority) {
        if(size(users_) <= taskId)
            users_.resize(taskId + 1);
        tasks_.push({taskId, priority});
        users_[taskId] = {userId, priority};
    }
    
    void edit(int taskId, int newPriority) {
        if(tasks_.top().task == taskId) tasks_.pop();
        tasks_.push({taskId, newPriority});
        users_[taskId].priority = newPriority;
    }
    
    void rmv(int taskId) {
        if(tasks_.top().task == taskId) tasks_.pop();
        users_[taskId].user = -1;
        users_[taskId].priority = -1;
    }
    
    int execTop() {
        // remove phantom tasks (with older priority)
        while(!tasks_.empty()) {
            if(tasks_.top().priority != users_[tasks_.top().task].priority)
                tasks_.pop();
            else break;
        }
        if(tasks_.empty()) return -1;
        // task with actual priority
        int user = users_[tasks_.top().task].user;
        users_[tasks_.top().task].user = -1;
        users_[tasks_.top().task].priority = -1;
        tasks_.pop();
        return user;
    }

private:
    struct Task {
        int task;
        int priority;
        bool operator<(const Task& rhs) const {
            if(priority == rhs.priority) return task < rhs.task;
            return priority < rhs.priority;
        }
    };

    priority_queue<Task> tasks_;

    struct User {
        int user = -1;
        int priority = -1;
    };
    
    vector<User> users_;
};
```
['C++']