voidput(int d) { int now, next; heap[++heap_size] = d; now = heap_size; while (now > 1) { next = now >> 1; if (heap[now] <= heap[next]) break; swap(heap[now], heap[next]); now = next; } return; }
intget() { int now, next, res; res = heap[1]; heap[1] = heap[heap_size--]; now = 1; while (now * 2 <= heap_size) { next = now * 2; if (next < heap_size && heap[next + 1] < heap[next]) next++; if (heap[now] <= heap[next]) break; swap(heap[now], heap[next]); now = next; } return res; }