|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|12 초||512 MB||4||4||4||100.000%|
You a given a permutation p1, p2, . . . , pn of size n. Initially, all elements in p are frozen. There will be n stages that these elements will become available one by one. On stage i, the element pki will become available.
For each i, find the longest increasing subsequence among available elements after the first i stages.
The first line of the input contains an integer T (1 ≤ T ≤ 3), denoting the number of test cases.
In each test case, there is one integer n (1 ≤ n ≤ 50 000) on the first line, denoting the size of permutation.
In the second line of each test case, there are n distinct integers p1, p2, . . . , pn (1 ≤ pi ≤ n), denoting the permutation.
In the third line of each test case, there are n distinct integers k1, k2, . . . , kn (1 ≤ ki ≤ n), describing each stage.
It is guaranteed that p1, p2, . . . , pn and k1, k2, . . . , kn are generated uniformly at random among all possible permutations of the given size.
For each test case, print a single line containing n integers, where the i-th integer denotes the length of the longest increasing subsequence among available elements after the first i stages.
1 5 2 5 3 1 4 1 4 5 3 2
1 1 2 3 3