1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| void down(int u) { int t = u; while (u * 2 <= cnt && h[u * 2] < h[t]) t = u * 2; while (u * 2 + 1 <= cnt && h[u * 2 + 1] < h[t]) t = u * 2 + 1; if (t != u) { swap(h[t], h[u]); down(t); } }
void up (int u) { while (u / 2 && h[u] < h[u / 2]) { swap(u, u / 2); u >>= 1; } }
|