結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー tentententen
提出日時 2022-09-07 11:06:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,989 bytes
コンパイル時間 3,369 ms
コンパイル使用メモリ 77,956 KB
実行使用メモリ 59,924 KB
最終ジャッジ日時 2024-05-02 04:13:06
合計ジャッジ時間 14,773 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
36,548 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 473 ms
54,644 KB
testcase_13 WA -
testcase_14 AC 455 ms
53,608 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 551 ms
58,924 KB
testcase_20 AC 575 ms
59,136 KB
testcase_21 AC 57 ms
36,844 KB
testcase_22 AC 58 ms
36,916 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 560 ms
56,536 KB
testcase_27 AC 57 ms
36,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
    
}
0