結果
| 問題 |
No.1768 The frog in the well knows the great ocean.
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-09-07 11:06:04 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,989 bytes |
| コンパイル時間 | 2,582 ms |
| コンパイル使用メモリ | 77,972 KB |
| 実行使用メモリ | 58,884 KB |
| 最終ジャッジ日時 | 2024-11-22 14:37:25 |
| 合計ジャッジ時間 | 13,851 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 WA * 19 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int t = sc.nextInt();
StringBuilder sb = new StringBuilder();
while(t-- > 0) {
int n = sc.nextInt();
SegmentTree st = new SegmentTree(n);
for (int i = 0; i < n; i++) {
st.setValue(i, sc.nextInt());
}
int prev = sc.nextInt();
int idx = 0;
boolean enable = true;
for (int i = 1; i < n; i++) {
int current = sc.nextInt();
if (current != prev) {
enable &= (st.getMax(idx, i) == prev);
idx = i;
prev = current;
}
}
enable &= (st.getMax(idx, n) == prev);
if (enable) {
sb.append("Yes\n");
} else {
sb.append("No\n");
}
}
System.out.print(sb);
}
static class SegmentTree {
int size;
int[] tree;
public SegmentTree(int size) {
this.size = 1;
while (size > this.size) {
this.size <<= 1;
}
tree = new int[this.size * 2 - 1];
}
public void setValue(int idx, int value) {
updateTree(size - 1 + idx, value);
}
private void updateTree(int idx, int value) {
tree[idx] = Math.max(tree[idx], value);
if (idx > 0) {
updateTree((idx - 1) / 2, tree[idx]);
}
}
public int getMax(int left, int right) {
return getMax(0, 0, size, left, right);
}
private int getMax(int idx, int min, int max, int left, int right) {
if (left <= min && max <= right) {
return tree[idx];
} else if (right <= min || max <= left) {
return 0;
} else {
return Math.max(getMax(idx * 2 + 1, min, (min + max) / 2, left, right), getMax(idx * 2 + 2, (min + max) / 2, max, left, right));
}
}
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten