#DSU0000033. Hoán vị dần biến mất (Disappearing Permutation)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hoán vị dần biến mất (Disappearing Permutation)
Disappearing Permutation
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given two permutations and of the integers from to . Initially, the array is . Its positions are then deleted in the order .
At step , the element at position is replaced by ; all positions deleted earlier remain . After this deletion, determine the minimum number of operations needed to turn the current array into a permutation of . A restoration operation chooses a position and assigns exactly the value to it.
Restoration operations are performed only hypothetically to compute each answer. They are not applied to the array used for subsequent deletions. Output one answer after every deletion, in order.
Input
The first line contains , the second the permutation , and the third the permutation .
Output
Print answers in query order.
Subtasks
- Subtask 1 (20 points): ; and are both permutations of .
- Subtask 2 (30 points): ; and are both permutations of .
- Subtask 3 (50 points): ; and are both permutations of .
Examples
Input
5
4 5 3 1 2
4 5 1 3 2
Output
2 4 4 5 5
Explanation
Once a deleted position touches a permutation cycle, repairing the array requires correcting that entire cycle.