Nonsense Time
Time limit12sMemory limit512 MB
Elements of a random permutation are unfrozen one at a time; after each unfreeze report the longest increasing subsequence length among the currently available elements.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Binary search, Greedy, Probability
- Solved
- No attempts yet
Problem
You are given a permutation of size n. Initially, all elements of p are frozen. Over n stages, the elements become available one by one. On stage i, the element becomes available.
For each i, find the longest increasing subsequence among the available elements after the first i stages.
Input
The first line of the input contains an integer T (1 ≤ T ≤ 3), the number of test cases.
In each test case, the first line contains one integer n (1 ≤ n ≤ 50 000), the size of the permutation.
In the second line of each test case, there are n distinct integers (1 ≤ ≤ n), the permutation.
In the third line of each test case, there are n distinct integers (1 ≤ ≤ n), describing each stage.
It is guaranteed that and are generated uniformly at random among all possible permutations of the given size.
Output
For each test case, print a single line containing n integers, where the i-th integer is the length of the longest increasing subsequence among the available elements after the first i stages.