(int num)
| 106 | } |
| 107 | |
| 108 | public static void add(int num) { |
| 109 | key[++cnt] = num; |
| 110 | size[cnt] = 1; |
| 111 | if (head == 0) { |
| 112 | head = cnt; |
| 113 | } else { |
| 114 | int f = 0, i = head, son = 0; |
| 115 | while (i != 0) { |
| 116 | f = i; |
| 117 | if (key[i] <= num) { |
| 118 | son = 1; |
| 119 | i = right[i]; |
| 120 | } else { |
| 121 | son = 0; |
| 122 | i = left[i]; |
| 123 | } |
| 124 | } |
| 125 | if (son == 1) { |
| 126 | right[f] = cnt; |
| 127 | } else { |
| 128 | left[f] = cnt; |
| 129 | } |
| 130 | father[cnt] = f; |
| 131 | splay(cnt, 0); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | public static int rank(int num) { |
| 136 | int i = head, last = head; |