------------ Recovery content started ------------
Translate as follows
(I did n’t understand after watching it for a long time) Then the big brother saw it at a glance (worship the big brother manually);
Just thinking when there is a difference between a bit in the upper array and a bit in the lower array, if the difference is less than 0, see if there is a 1 in front;
Greater than 0 to see if there is -1 in front;
practice:
-1 position and the position of the first occurrence of a memory map with the first occurrence, then iterates again to see if feasible; big brother approach ↓↓↓↓↓
1 #include<bits/stdc++.h>
2 const int maxn=1e5+50;
3 const int INF=0x3f3f3f3f;
4 using namespace std;
5 int a[maxn],b[maxn];
6 int main(){
7 int t;
8 cin>>t;
9 while(t--) {
10 int n;
11 int flag=0,flag1=0,flag2=0;
12 map<int,int> m;
13 m[1]=INF,m[-1]=INF;
14 cin>>n;
15 for(int i=1;i<=n;i++)
16 cin>>a[i];
17 for(int i=1;i<=n;i++)
18 cin>>b[i];
19 for(int i=1;i<=n;i++){
20 if(a[i]==1&&!flag1) {// Record 1 first occurrence position
21 flag1 = 1 ;
22 m [ 1 ] = i;
23 }
24 if (a [i] ==- 1 &&! flag2) {// Record -1 One occurrence position
25 flag2 = 1 ;
26 m [ -1 ] = i;
27 }
28 }
29 for ( int i = 1 ; i <= n; i ++ ) {
30 if (a [i]> b [i ]) {
31 if(m [ -1 ]> = i) {// Compare when the upper and lower elements are different, whether there has been the previous
32 flag = 1 ;
33 break ;
34 }
35 }
36 else if (a [i] < b [i]) {
37 if (m [ 1 ]> = i) {
38 flag = 1 ;
39 break ;
40 }
41 }
42 }
43 if (flag)
44 cout << "NO"<<'\n';
45 else
46 cout<<"YES"<<'\n';
47 }
48 return 0;
49 }