CF1647E.Madoka and the Sixth-graders

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

After the most stunning success with the fifth-graders, Madoka has been trusted with teaching the sixth-graders.

There's nn single-place desks in her classroom. At the very beginning Madoka decided that the student number bib_i ( 1bin1 \le b_i \le n ) will sit at the desk number ii . Also there's an infinite line of students with numbers n+1,n+2,n+3,n + 1, n + 2, n + 3, \ldots waiting at the door with the hope of being able to learn something from the Madoka herself. Pay attention that each student has his unique number.

After each lesson, the following happens in sequence.

  1. The student sitting at the desk ii moves to the desk pip_i . All students move simultaneously.
  2. If there is more than one student at a desk, the student with the lowest number keeps the place, and the others are removed from the class forever.
  3. For all empty desks in ascending order, the student from the lowest number from the outside line occupies the desk.

Note that in the end there is exactly one student at each desk again. It is guaranteed that the numbers pp are such that at least one student is removed after each lesson. Check out the explanation to the first example for a better understanding.

After several (possibly, zero) lessons the desk ii is occupied by student aia_i . Given the values a1,a2,,ana_1, a_2, \ldots, a_n and p1,p2,,pnp_1, p_2, \ldots, p_n , find the lexicographically smallest suitable initial seating permutation b1,b2,,bnb_1, b_2, \ldots, b_n .

The permutation is an array of nn different integers from 11 up to nn in any order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not ( 22 occurs twice). [1,3,4][1,3,4] is not a permutation either ( n=3n=3 but there's 44 in the array).

For two different permutations aa and bb of the same length, aa is lexicographically less than bb if in the first position where aa and bb differ, the permutation aa has a smaller element than the corresponding element in bb .

输入格式

The first line of input data contains an integer nn ( 2n1052 \le n \le 10^5 ) — a number of desks in the classroom.

The second line contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n ( 1pin1 \leq p_i \leq n ) — desks where the students move. It is guaranteed that pp has at least two equal elements.

The third line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1091 \leq a_i \leq 10^9 ) — the final seating of the students. It is guaranteed that there is an initial permutation from which the seating aa can be obtained.

输出格式

In the only line print nn integers b1,b2,,bnb_1, b_2, \ldots, b_n ( 1bin1 \le b_i \le n ) — lexicographically minimum permutation describing the initial seating of the sixth-graders that can lead to the final seating aa .

输入输出样例

  • 输入#1

    5
    5 5 3 3 1
    1 8 2 9 4

    输出#1

    1 3 2 5 4
  • 输入#2

    5
    1 3 2 5 2
    3 2 5 4 1

    输出#2

    3 2 5 4 1
  • 输入#3

    10
    10 8 5 3 7 8 6 6 1 1
    5 26 24 27 21 4 18 2 28 1

    输出#3

    5 4 2 6 7 8 3 9 1 10

说明/提示

The description of the first test is below:

The first picture shows the starting permutation, which is the answer. Then the students sitting at desks 1,21, 2 are transferred to a 55 desk. Also, a 11 student moved from a 55 desk, and a student from a 44 disk is transferred to a 33 desk.

Thus, after all these transfers permutation shown in the second image is obtained. Then, at the desk with the number 55 , the student with the number 33 is expelled, and at the desk with the number 33 , the student with the number 55 is expelled. (Since their numbers are not the smallest) Then new students with numbers 6,76, 7 sit at desks numbered 2,42, 4 . And this permutation (after the end of the first lesson) is shown in the third image.

The 44 image shows the seating arrangement, after the second lesson before all the extra ones were kicked out. And the fifth shows the final seating after 22 lesson.

首页