其他分享
首页 > 其他分享> > Kind Anton CodeForces - 1333B思维

Kind Anton CodeForces - 1333B思维

作者:互联网

Once again, Boris needs the help of Anton in creating a task. This time Anton needs to solve the following problem:

There are two arrays of integers aa and bb of length nn. It turned out that array aa contains only elements from the set {−1,0,1}{−1,0,1}.

Anton can perform the following sequence of operations any number of times:

  1. Choose any pair of indexes (i,j)(i,j) such that 1≤i<j≤n1≤i<j≤n. It is possible to choose the same pair (i,j)(i,j) more than once.
  2. Add aiai to ajaj. In other words, jj-th element of the array becomes equal to ai+ajai+aj.

For example, if you are given array [1,−1,0][1,−1,0], you can transform it only to [1,−1,−1][1,−1,−1], [1,0,0][1,0,0] and [1,−1,1][1,−1,1] by one operation.

Anton wants to predict if it is possible to apply some number (zero or more) of these operations to the array aa so that it becomes equal to array bb. Can you help him?

Input

Each test contains multiple test cases.

The first line contains the number of test cases tt (1≤t≤100001≤t≤10000). The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1051≤n≤105)  — the length of arrays.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (−1≤ai≤1−1≤ai≤1)  — elements of array aa. There can be duplicates among elements.

The third line of each test case contains nn integers b1,b2,…,bnb1,b2,…,bn (−109≤bi≤109−109≤bi≤109)  — elements of array bb. There can be duplicates among elements.

It is guaranteed that the sum of nn over all test cases doesn't exceed 105105.

Output

For each test case, output one line containing "YES" if it's possible to make arrays aa and bb equal by performing the described operations, or "NO" if it's impossible.

You can print each letter in any case (upper or lower).

Example

Input
5
3
1 -1 0
1 1 -2
3
0 1 1
0 2 2
2
1 0
1 41
2
-1 0
-1 -41
5
0 1 -1 1 -1
1 1 -1 1 -1
Output
YES
NO
YES
YES
NO

Note

In the first test-case we can choose (i,j)=(2,3)(i,j)=(2,3) twice and after that choose (i,j)=(1,2)(i,j)=(1,2) twice too. These operations will transform [1,−1,0]→[1,−1,−2]→[1,1,−2][1,−1,0]→[1,−1,−2]→[1,1,−2]

In the second test case we can't make equal numbers on the second position.

In the third test case we can choose (i,j)=(1,2)(i,j)=(1,2) 4141 times. The same about the fourth test case.

In the last lest case, it is impossible to make array aa equal to the array bb.

//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include<cstring>
#include <algorithm>
#include <queue>
#include<map>
#include<set>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 1e9;
const int mod = 1000000007;
const int mx = 5e5+10; //check the limits, dummy
typedef pair<int, int> pa;
const double PI = acos(-1);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
#define swa(a,b) a^=b^=a^=b
#define re(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define rb(i,a,b) for(int i=(a),_=(b);i>=_;i--)
#define clr(a) memset(a, -1, sizeof(a))
#define lowbit(x) ((x)&(x-1))
#define mkp make_pai
void sc(int& x) { scanf("%d", &x); }void sc(int64_t& x) { scanf("%lld", &x); }void sc(double& x) { scanf("%lf", &x); }void sc(char& x) { scanf(" %c", &x); }void sc(char* x) { scanf("%s", x); }
int n, m, k,ans=mx,t,p,x;
int a[mx], sum[mx],pos[mx],room[mx];
void solve() {
    cin >> n;
    vector<int>a(n), b(n);
    re(i, 0, n)cin >> a[i];
    re(i, 0, n)cin >> b[i];
    vector<int>fuck(2, 0);
    re(i, 0, n) {
        if (a[i] > b[i] && !fuck[0]) {
            puts("NO");
            return;
        }
        else if (a[i] < b[i] && !fuck[1]) {
            puts("NO");
            return;
        }
        if (a[i] == -1)fuck[0] = 1;
        if (a[i] == 1)fuck[1] = 1;
    }
    puts("YES");
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);    
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

 

标签:case,Kind,int,Anton,void,CodeForces,test,array,include
来源: https://www.cnblogs.com/xxxsans/p/12765201.html