結果
| 問題 | No.1768 The frog in the well knows the great ocean. | 
| コンテスト | |
| ユーザー | 👑  SPD_9X2 | 
| 提出日時 | 2021-11-26 23:57:01 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 1,317 bytes | 
| コンパイル時間 | 393 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 129,324 KB | 
| 最終ジャッジ日時 | 2024-06-29 19:09:02 | 
| 合計ジャッジ時間 | 6,051 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 26 WA * 1 | 
ソースコード
import sys
from sys import stdin
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
    N = int(stdin.readline())
    A = list(map(int,stdin.readline().split()))
    B = list(map(int,stdin.readline().split()))
    flag = True
    for i in range(N):
        if A[i] > B[i]:
            flag = False
    able = [False] * N
    stk = []
    stkset = set()
    
    for i in range(N):
        while len(stk) > 0 and stk[-1] <= A[i]:
            stkset.remove(stk[-1])
            del stk[-1]
        stk.append(A[i])
        stkset.add(A[i])
        if B[i] in stkset:
            able[i] = True
    A.reverse()
    B.reverse()
    stk = []
    stkset = set()
    
    for i in range(N):
        while len(stk) > 0 and stk[-1] <= A[i]:
            stkset.remove(stk[-1])
            del stk[-1]
        stk.append(A[i])
        stkset.add(A[i])
        if B[i] in stkset:
            able[N-1-i] = True
    A.reverse()
    B.reverse()
    if False in able:
        flag = False
    B2 = []
    for i in B:
        if len(B2) == 0 or B2[-1] != i:
            B2.append(i)
    for i in range(N-1,-1,-1):
        if len(B2) > 0 and B2[-1] == A[i]:
            del B2[-1]
    if B2:
        flag = False
    if flag:
        ANS.append("Yes")
    else:
        ANS.append("No")
print ("\n".join(ANS))
            
            
            
        