inlineintread(){ registerchar c; for (c = getchar(); (c < '0' || c>'9') && c != '-'; c = getchar()); registerbool f = c == '-'; registerint s = f ? 0 : c - '0'; for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) { s = (s << 3) + (s << 1) + c - '0'; } return f ? -s : s; }
int heap[MAXn + 10]; int heapn; int n; voidUp(int p){ int f = p / 2; while (p > 1) { if (heap[p] < heap[f]) { swap(heap[p], heap[f]); p = f; f /= 2; } elsebreak; } } voidDown(int p){ int s = p * 2; while (s <= heapn) { if (heap[s] > heap[s + 1] && s < heapn) { s++; } if (heap[s] < heap[p]) { swap(heap[s], heap[p]); p = s; s *= 2; } elsebreak; } } voidInsert(int x){ heap[++heapn] = x; Up(heapn); } voidPop(int p){ heap[p] = heap[heapn--]; Up(p); Down(p); } voidPopRoot(){ heap[1] = heap[heapn--]; Down(1); } intGetRoot(){ return heap[1]; }
intmain(){ int opt; n = read(); while (n--) { opt = read(); switch (opt) { case1: Insert(read()); break; case2: printf("%d\n", GetRoot()); break; case3: PopRoot(); break; } } }
inlineintread(){ registerchar c; for (c = getchar(); (c < '0' || c>'9') && c != '-'; c = getchar()); registerbool f = c == '-'; registerint s = f ? 0 : c - '0'; for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) { s = (s << 3) + (s << 1) + c - '0'; } return f ? -s : s; }
int heap[MAXn + 10]; int heapn; int n; voidUp(int p){ int f = p / 2; while (p > 1) { if (heap[p] > heap[f]) { swap(heap[p], heap[f]); p = f; f /= 2; } elsebreak; } } voidDown(int p){ int s = p * 2; while (s <= heapn) { if (heap[s] < heap[s + 1] && s < heapn) { s++; } if (heap[s] > heap[p]) { swap(heap[s], heap[p]); p = s; s *= 2; } elsebreak; } } voidInsert(int x){ heap[++heapn] = x; Up(heapn); } voidPop(int p){ heap[p] = heap[heapn--]; Up(p); Down(p); } voidPopRoot(){ heap[1] = heap[heapn--]; Down(1); } intGetRoot(){ return heap[1]; }