CF1647E.Madoka and the Sixth-graders
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
After the most stunning success with the fifth-graders, Madoka has been trusted with teaching the sixth-graders.
There's n single-place desks in her classroom. At the very beginning Madoka decided that the student number bi (1≤bi≤n) will sit at the desk number i. Also there's an infinite line of students with numbers n+1,n+2,n+3,… 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.
- The student sitting at the desk i moves to the desk pi. All students move simultaneously.
- 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.
- 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 p 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 i is occupied by student ai. Given the values a1,a2,…,an and p1,p2,…,pn, find the lexicographically smallest suitable initial seating permutation b1,b2,…,bn.
The permutation is an array of n different integers from 1 up to n in any order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not (2 occurs twice). [1,3,4] is not a permutation either (n=3 but there's 4 in the array).
For two different permutations a and b of the same length, a is lexicographically less than b if in the first position where a and b differ, the permutation a has a smaller element than the corresponding element in b.
在对五年级学生取得惊人成功后,麻美被委以教导六年级学生的重任。
她的教室里有 n 张单人课桌。最开始,麻美决定编号为 bi(其中 1≤bi≤n)的学生坐在第 i 号课桌。此外,门外还排着一支无限长的学生队伍,编号依次为 n+1,n+2,n+3,…,他们都渴望能从麻美老师那里学到知识。请注意:每位学生都有唯一的编号。
每节课结束后,将按以下顺序发生如下事件:
- 坐在第 i 号课桌的学生移动到第 pi 号课桌。所有学生同时移动。
- 若某张课桌上有超过一名学生,则编号最小的学生保留该座位,其余学生将被永远逐出课堂。
- 对于所有空置的课桌(按课桌编号升序排列),门外队伍中编号最小的学生依次入座。
注意:最终每张课桌上恰好又只有一名学生。题目保证所给的排列 p 满足:每节课后至少有一名学生被移除。请参阅第一个样例的解释以加深理解。
经过若干次(可能为零次)课程后,第 i 号课桌上的学生编号为 ai。已知 a1,a2,…,an 和 p1,p2,…,pn,求字典序最小的合法初始座位安排排列 b1,b2,…,bn。
所谓排列,是指由 1 到 n 的 n 个互不相同的整数构成的任意顺序的数组。例如,[2,3,1,5,4] 是一个排列,而 [1,2,2] 不是(数字 2 出现了两次);[1,3,4] 也不是排列(此时 n=3,但数组中出现了 4)。
对于两个长度相同的不同的排列 a 和 b,若在 a 与 b 首次出现差异的位置上,a 中对应位置的元素小于 b 中对应位置的元素,则称 a 的字典序小于 b。
输入格式
The first line of input data contains an integer n (2≤n≤105) — a number of desks in the classroom.
The second line contains n integers p1,p2,…,pn (1≤pi≤n) — desks where the students move. It is guaranteed that p has at least two equal elements.
The third line contains n integers a1,a2,…,an (1≤ai≤109) — the final seating of the students. It is guaranteed that there is an initial permutation from which the seating a can be obtained.
输入数据的第一行包含一个整数 n(2≤n≤105)—— 教室中课桌的数量。
第二行包含 n 个整数 p1,p2,…,pn(1≤pi≤n)—— 学生移动至的课桌编号。保证数组 p 中至少有两个相等的元素。
第三行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 学生的最终就座情况。保证存在某个初始排列,能通过题目描述的过程得到座位安排 a。
输出格式
In the only line print n integers b1,b2,…,bn (1≤bi≤n) — lexicographically minimum permutation describing the initial seating of the sixth-graders that can lead to the final seating a.
在唯一的一行中输出 n 个整数 b1,b2,…,bn(1≤bi≤n),即字典序最小的排列,它描述了六年级学生初始就座情况,且该初始就座能导致最终就座情况 a。
输入输出样例
输入#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,2 are transferred to a 5 desk. Also, a 1 student moved from a 5 desk, and a student from a 4 disk is transferred to a 3 desk.
Thus, after all these transfers permutation shown in the second image is obtained. Then, at the desk with the number 5, the student with the number 3 is expelled, and at the desk with the number 3, the student with the number 5 is expelled. (Since their numbers are not the smallest) Then new students with numbers 6,7 sit at desks numbered 2,4. And this permutation (after the end of the first lesson) is shown in the third image.
The 4 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 2 lesson.
第一次测试的描述如下:

第一张图显示的是初始排列,即所求答案。接着,坐在第 1 号和第 2 号课桌的学生被调至第 5 号课桌;同时,一名编号为 1 的学生从第 5 号课桌离开,一名来自第 4 号课桌的学生被调至第 3 号课桌。
因此,经过上述所有调动后,得到第二张图所示的排列。随后,在编号为 5 的课桌上,编号为 3 的学生被开除;在编号为 3 的课桌上,编号为 5 的学生被开除(因为他们的编号均非最小)。接着,编号为 6 和 7 的新学生分别入座第 2 号和第 4 号课桌。该排列(即第一节课结束后的最终状态)如第三张图所示。
第四张图显示的是第二节课结束后、所有被开除者尚未离场前的座位安排;第五张图则显示经过两节课后的最终座位安排。
输入解题思路,AI测评打分。不知道怎么写?