結果
問題 | No.1768 The frog in the well knows the great ocean. |
ユーザー | tenten |
提出日時 | 2022-09-07 11:06:04 |
言語 | Java21 (openjdk 21) |
結果 |
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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
36,848 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 423 ms
53,392 KB |
testcase_13 | WA | - |
testcase_14 | AC | 480 ms
54,356 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 491 ms
55,064 KB |
testcase_20 | AC | 450 ms
55,048 KB |
testcase_21 | AC | 53 ms
36,896 KB |
testcase_22 | AC | 54 ms
36,892 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 535 ms
55,648 KB |
testcase_27 | AC | 53 ms
36,628 KB |
ソースコード
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(); } }