-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-b-1079.java
More file actions
35 lines (34 loc) · 1.21 KB
/
Copy pathproblem-b-1079.java
File metadata and controls
35 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
while (t-- > 0) {
int n = Integer.parseInt(br.readLine());
int[] p = new int[n + 1];
int[] pos = new int[n + 1];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 1; i <= n; i++) {
p[i] = Integer.parseInt(st.nextToken());
pos[p[i]] = i;
}
int[] a = new int[n + 1];
st = new StringTokenizer(br.readLine());
for (int i = 1; i <= n; i++)a[i] = Integer.parseInt(st.nextToken());
boolean ok = true;
int last = 0;
for (int i = 1; i <= n; i++) {
int cur = pos[a[i]];
if (cur < last) {
ok = false;
break;
}
last = cur;
}
sb.append(ok ? "YES\n" : "NO\n");
}
System.out.print(sb);
}
}