結果
問題 |
No.3134 二分探索木
|
ユーザー |
![]() |
提出日時 | 2025-05-02 21:38:24 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 950 bytes |
コンパイル時間 | 404 ms |
コンパイル使用メモリ | 82,292 KB |
実行使用メモリ | 273,536 KB |
最終ジャッジ日時 | 2025-05-02 21:38:31 |
合計ジャッジ時間 | 6,084 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 8 TLE * 1 -- * 6 |
ソースコード
class Node: def __init__(self, i, a): self.left = None self.right = None self.i = i self.a = a def insert(self, i, a): if a < self.a: if self.left is not None: self.left.insert(i, a) else: self.left = Node(i, a) else: if self.right is not None: self.right.insert(i, a) else: self.right = Node(i, a) def out(self, ans, d=0): i = self.i c = 0 if self.left is not None: c += self.left.out(ans, d+1) if self.right is not None: c += self.right.out(ans, d+1) ans[i] = (d, c) return c + 1 N = int(input()) A = list(map(int, input().split())) root = Node(0, A[0]) for i, a in enumerate(A): if not i: continue root.insert(i, a) ans = [None]*N root.out(ans) b, c = zip(*ans) print(*b) print(*c)