P13822 「Diligent-OI R2 B」Dew and Frost Gleam
Background
Ns6 couldn't solve [ARC146E](/problem/AT_arc146_e), so he created this problem.
Description
A sequence $a_1,a_2,\dots,a_n$ is called a **polyline** if and only if for $i=1,2,\dots,n-1$, the condition $|a_i-a_{i+1}|=1$ is satisfied. Specifically, a sequence of length $1$ is also considered a polyline.
Given $n$ and two sequences $a$ and $b$ of length $n$, where both $a$ and $b$ are polylines, you can perform the following operation on $a$ any number of times:
Choose an integer $1\le i\le n$ and modify $a_i$ to any value, but you must ensure that after the modification, the sequence $a$ remains a polyline.
The question is: Can you make $a$ equal to $b$? **Note: You do not need to print the operation steps.**
Input Format
**Note that this problem requires efficient input and output methods.**
The input consists of multiple test cases. The first line contains $T$, the number of test cases.
For each test case:
The first line contains $n$.
The second line contains $n$ integers $a_1,a_2,\dots,a_n$.
The third line contains $n$ integers $b_1,b_2,\dots,b_n$.
Output Format
For each test case, output one line. If it is impossible to make $a$ equal to $b$, output `No`; otherwise, output `Yes`. **Note: You do not need to print the operation steps.**
Explanation/Hint
#### Sample #1 Explanation
First test case: $\{1\}\rarr\{2\}$.
Second test case: $\{1,2,3,4\}\rarr\{3,2,3,4\}\rarr\{3,2,3,2\}$.
Third test case: It can be proven that there is no solution.
#### Data Range
Let $N$ be the sum of $n$ across all test cases in a single test point.
For $100\%$ of the data, $1\le T\le10^6,1\le n\le10^6,1\le N\le10^6,1\le a_i\le10^9$.
- Testcase 1: $n=1$.
- Testcase 2: $n\le2$.
- Testcase 3: $T\le 5,n\le 4,a_i,b_i\le4$.
- Testcase 4: For any $1\le i\le n$, $b_i=a_i+1$.
- Testcase 5: No additional constraints.