B. Kind Anton
题目链接-B. Kind Anton
题目大意
数组
由 {
} 中的元素构成,并且你可以将数组中的任意元素
替换为
,问数组
能否通过变换变成数组
解题思路
- 因为只能用前面的数字来改变后面的,所以从后向前模拟即可
- 如果
,那么必须存在
;如果
,那么必须存在
,如果不满足条件就输出
NO
- 具体操作见代码
附上代码
#pragma GCC optimize("-Ofast","-funroll-all-loops")
//#pragma GCC diagnostic error "-std=c++11"
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+10;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
int a[N],b[N];
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
map<int,int> mp;
bool ass=1;
for(int i=0;i<n;i++){
cin>>a[i];
mp[a[i]]++;
}
for(int i=0;i<n;i++)
cin>>b[i];
for(int i=n-1;i>=0;i--){
mp[a[i]]--;
if(b[i]>a[i]&&!mp[1]){
ass=0;
break;
}
if(b[i]<a[i]&&!mp[-1]){
ass=0;
break;
}
}
ass?cout<<"YES"<<endl:cout<<"NO"<<endl;
}
return 0;
}