题目
题意:
给你一个序列 和一个序列 你可以选择两个下标 ,然后 ,问最后的序列会不会等于 。
思路:
因为 ,所以假如 出现过 的情况的时候,那么只要 的话,都可以通过无限次累加达到一样的, 的时候同理。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
inline void out(int x) {
if (x > 9) out(x / 10);
putchar(x % 10 + '0');
}
const int maxn = 100010;
int a[maxn], b[maxn];
int main() {
int t, n;
read(t);
while (t--) {
read(n);
for (int i = 0; i < n; i++) read(a[i]);
for (int i = 0; i < n; i++) read(b[i]);
bool cnt_1 = false, cnt1 = false, flag = false;
for (int i = 0; i < n; i++) {
if (a[i] < b[i] && !cnt1) {
flag = true;
break;
} else if (a[i] > b[i] && !cnt_1) {
flag = true;
break;
}
if (a[i] == -1) cnt_1 = true;
else if (a[i] == 1) cnt1 = true;
if (cnt1 && cnt_1) break;
}
if (flag) printf("NO\n");
else printf("YES\n");
}
return 0;
}