Simple Solution using Hashmap and Treeset (Java)
IntuitionThe problem is quite simple, the obstacle that we need to take care of is efficient and quick lookup of tasks. For quick retrieval, we store all tasks
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem is quite simple, the obstacle that we need to take care of is efficient and quick lookup of tasks. For quick retrieval, we store all tasks in a hashmap. To keep the tasks sorted, we use a treeset (which also allows for efficient lookup during remove and edit operations).

# Approach
<!-- Describe your approach to solving the problem. -->
- **Add operation:** Store each task as an array of three elements: {userId, taskId, priority}.
- **Edit operation:** Rather than directly changing the priority to newPriority, delete that task first from sorted treeset before reinserting. This ensures correct order. Both sorted treeset and hashmap store the same array reference (the task), hence a change made in the task is reflected in both.
- **Execute top:** The task to be executed is present at the top of sorted treeset. It is retrieved while deletion from the treeset. It is removed from the hashmap using its taskId.

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


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

# Code
```java []
class TaskManager {
    private final HashMap<Integer, int[]> taskMap;
    private final TreeSet<int[]> sortedTasks;

    public TaskManager(List<List<Integer>> tasks) {
        taskMap = new HashMap<>();
        sortedTasks = new TreeSet<>((t1, t2) -> t2[2] != t1[2] ? t2[2] - t1[2] : t2[1] - t1[1]);

        for (List<Integer> task : tasks) {
            add(task.getFirst(), task.get(1), task.getLast());
        }
    }
    
    public void add(int userId, int taskId, int priority) {
        int[] task = new int[] {userId, taskId, priority};
        taskMap.put(taskId, task);
        sortedTasks.add(task);
    }
    
    public void edit(int taskId, int newPriority) {
        int[] task = taskMap.get(taskId);
        sortedTasks.remove(task);
        task[2] = newPriority;
        sortedTasks.add(task);
    }
    
    public void rmv(int taskId) {
        int[] task = taskMap.remove(taskId);
        sortedTasks.remove(task);
    }
    
    public int execTop() {
        if (sortedTasks.isEmpty()) return -1;
        int[] task = sortedTasks.removeFirst();
        taskMap.remove(task[1]);
        return task[0];
    }
}

/**
 * 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();
 */
```
['Java']