An Alternative Way
Description:
You are given two arrays and , each of length . You are allowed to perform the following operation on array any number of times (including zero):
- Choose two indices and such that ;
- For each index from to (both inclusive),
- Set if is odd.
- Set if is even.
Determine whether you can make the array equal to the array by performing the operation any number of times.
Input The first line contains a single integer () — the number of test cases. The first line of each test case contains a single integer () — the length of the arrays. The second line contains integers . The third line contains integers .
Output For each test case, print "YES" if you can make array equal to array and "NO" otherwise.
Approaches:
1. Prefix Sum Invariant (Optimal)
Whenever an array operation involves alternating additions and subtractions (like