QHEAP1

  • + 0 comments

    Java O(Q log n)

     public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int Q = scanner.nextInt();
            
            PriorityQueue<Integer> heap = new PriorityQueue<>();
    
            for (int i = 0; i < Q; i++) {
                int queryType = scanner.nextInt();
    
                switch (queryType) {
                    case 1:
                        int elementToAdd = scanner.nextInt();
                        heap.add(elementToAdd);
                        break;
                    case 2:
                        int elementToDelete = scanner.nextInt();
                        heap.remove(elementToDelete);
                        break;
                    case 3:
                        System.out.println(heap.peek());
                        break;
                }
            }
            scanner.close();
        }