結果
| 問題 |
No.3134 二分探索木
|
| コンテスト | |
| ユーザー |
ID 21712
|
| 提出日時 | 2025-04-30 02:27:12 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,634 bytes |
| コンパイル時間 | 3,412 ms |
| コンパイル使用メモリ | 80,980 KB |
| 実行使用メモリ | 69,828 KB |
| 最終ジャッジ日時 | 2025-04-30 02:27:39 |
| 合計ジャッジ時間 | 23,662 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 7 TLE * 8 |
ソースコード
import java.io.*;
import java.lang.*;
import java.util.*;
class Main {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int N = in.nextInt();
int[] B = new int[N], C = new int[N];
TreeMap<Key, Item> map = new TreeMap<>();
Item item = new Item(1, N, 0);
map.put(item.key, item);
for (int i = 0; i < N; i++) {
int a = in.nextInt();
item = map.remove(new Key(a, a));
B[i] = item.depth;
C[i] = item.key.ub - item.key.lb;
for (Item tmp : item.split(a)) {
map.put(tmp.key, tmp);
}
}
for (int i = 0; i < N; i++) {
if (i > 0) System.out.print(" ");
System.out.print(B[i]);
}
System.out.println();
for (int i = 0; i < N; i++) {
if (i > 0) System.out.print(" ");
System.out.print(C[i]);
}
System.out.println();
}
}
class Key implements Comparable<Key> {
int lb, ub;
Key(int lb, int ub) {
this.lb = lb;
this.ub = ub;
}
public int compareTo(Key o) {
if (this.ub < o.lb) {
return -1;
} else if (o.ub < this.lb) {
return 1;
} else {
return 0;
}
}
}
class Item {
Key key;
int depth;
Item(int lb, int ub, int depth) {
this.key = new Key(lb, ub);
this.depth = depth;
}
Item[] split(int a) {
if (key.lb == a && key.ub == a) {
return new Item[0];
} else if (key.lb == a) {
return new Item[] { new Item(a+1, key.ub, depth+1) };
} else if (key.ub == a) {
return new Item[] { new Item(key.lb, a-1, depth+1) };
} else {
return new Item[] {
new Item(key.lb, a-1, depth+1),
new Item(a+1, key.ub, depth+1)
};
}
}
}
ID 21712