No.1768 The frog in the well knows the great ocean.
タグ : / 解いたユーザー数 48
作問者 :
Note
The time limit for this problem is $3$ seconds.
Problem Statement
You are given sequences $A,B$ of length $N$. Determine whether $A$ can be made equal to $B$ by performing the following operation $0$ or more times.
- Choose integers $l,r\ (1 \le l \le r \le N)$ and replace all of $A_l,A_{l+1},\dots,A_r$ with their maximum value.
You are given $T$ test cases; find the answer for each of them.
Input
$T$ $case_1$ $case_2$ $\vdots$ $case_T$
Each test case is given in the following format.
$N$ $A_1$ $A_2$ $\dots$ $A_N$ $B_1$ $B_2$ $\dots$ $B_N$
- All input values are integers.
- $1 \le T \le 2 \times 10^5$
- $1 \le N \le 2 \times 10^5$
- $1 \le A_i,B_i \le N$
- In $1$ input file, the sum of $N$ does not exceed $2 \times 10^5$.
Output
Output $T$ lines.
On line $i\ (1 \le i \le T)$, for the $i$-th test case, output Yes if $A$ can be made equal to $B$, and No otherwise, followed by a newline.
Sample
Sample 1
Input
4 2 2 1 2 2 4 2 1 2 2 2 2 2 1 5 1 3 1 2 3 3 3 4 4 4 7 2 4 1 6 2 2 1 2 6 6 6 6 2 2
Output
Yes No No Yes
In test case $1$, the sequences can be made equal by performing the operation with $(l,r)=(1,2)$.
In test cases $2,3$, the sequences cannot be made equal no matter how the operations are performed.
In test case $4$, the sequences can be made equal by performing the operations $(l,r)=(5,7),(l,r)=(2,5)$ in this order.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。