(int x)
| 63 | } |
| 64 | |
| 65 | public static void rotate(int x) { |
| 66 | int f = fa[x], g = fa[f]; |
| 67 | if (lr(x) == 0) { |
| 68 | ls[f] = rs[x]; |
| 69 | if (ls[f] != 0) { |
| 70 | fa[ls[f]] = f; |
| 71 | } |
| 72 | rs[x] = f; |
| 73 | } else { |
| 74 | rs[f] = ls[x]; |
| 75 | if (rs[f] != 0) { |
| 76 | fa[rs[f]] = f; |
| 77 | } |
| 78 | ls[x] = f; |
| 79 | } |
| 80 | if (!isroot(f)) { |
| 81 | if (lr(f) == 0) { |
| 82 | ls[g] = x; |
| 83 | } else { |
| 84 | rs[g] = x; |
| 85 | } |
| 86 | } |
| 87 | fa[f] = x; |
| 88 | fa[x] = g; |
| 89 | up(f); |
| 90 | up(x); |
| 91 | } |
| 92 | |
| 93 | public static void splay(int x) { |
| 94 | int siz = 0; |