欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1073B.Vasya and Books
Vasya and Books
Vasya has got books, numbered from to , arranged in a stack. The topmost book has number , the next one — , and so on. The book at the bottom of the stack has number . All numbers are distinct.
Vasya wants to move all the books to his backpack in steps. During -th step he wants to move the book number into his backpack. If the book with number is in the stack, he takes this book and all the books above the book , and puts them into the backpack; otherwise he does nothing and begins the next step. For example, if books are arranged in the order (book is the topmost), and Vasya moves the books in the order , then during the first step he will move two books ( and ), during the second step he will do nothing (since book is already in the backpack), and during the third step — one book (the book number ). Note that are distinct.
Help Vasya! Tell him the number of books he will put into his backpack during each step.
Input
The first line contains one integer — the number of books in the stack.
The second line contains integers denoting the stack of books.
The third line contains integers denoting the steps Vasya is going to perform.
All numbers are distinct, the same goes for .
Output
Print integers. The -th of them should be equal to the number of books Vasya moves to his backpack during the -th step.
Note
The first example is described in the statement.
In the second example, during the first step Vasya will move the books . After that only books and remain in the stack ( is above ). During the second step Vasya will take the books and . After that the stack becomes empty, so during next steps Vasya won't move any books.
Samples
3
1 2 3
2 1 3
2 0 1
5
3 1 4 2 5
4 5 1 3 2
3 2 0 0 0
6
6 5 4 3 2 1
6 5 3 4 2 1
1 1 2 0 1 1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |