zoukankan      html  css  js  c++  java
  • Kind Anton CodeForces

    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 1i<jn1≤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 (1t100001≤t≤10000). The description of the test cases follows.

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

    The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (1ai1−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 (109bi109−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;
    }
  • 相关阅读:
    .net Ioc 之 Unity 适合刚开始使用
    今天研究Unity Ioc 框架
    C#连接周立功CAN盒,调用ZCAN_OpenDevice函数时返回值一直是0失败。
    CAN通讯
    初学winform 自定义控件
    linq联表查询的时候报错
    dot net core 在IIS发布后,打开网页报错
    网卡驱动正常,网线也正常,但是网线插入电脑网口,网口指示灯就是不亮,网络适配器显示网线拔出
    flutter环境配置(windows)
    C#连接oracle数据库报错:OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用
  • 原文地址:https://www.cnblogs.com/xxxsans/p/12765201.html
Copyright © 2011-2022 走看看