-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisappearingperm.java
More file actions
47 lines (35 loc) · 1.06 KB
/
Copy pathdisappearingperm.java
File metadata and controls
47 lines (35 loc) · 1.06 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
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.*;
import java.io.*;
public class DisappearingPermutation {
public static void solve(Scanner sc) {
int n = sc.nextInt();
int[] p = new int[n];
int[] d = new int[n];
int[] pos = new int[n + 1];
for (int i = 0; i < n; i++) {
p[i] = sc.nextInt();
pos[p[i]] = i;
}
for (int i = 0; i < n; i++) {
d[i] = sc.nextInt() - 1;
}
int maxm = 0;
int[] res = new int[n];
Set<Integer> rem = new HashSet<>();
for (int i = 0; i < n; i++) {
rem.add(d[i]);
maxm = Math.max(maxm, pos[d[i] + 1]);
res[i] = rem.size() + (n - maxm - 1);
}
for (int x : res) System.out.print(x + " ");
System.out.println();
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
solve(sc);
}
sc.close();
}
}