#AT0076. Vasya and Books
Vasya and Books
题面翻译
题目描述
Vasya 有 本书,编号从 到 ,放在一个栈中,最上面的书的编号为 ,下一本书为 ,以此类推,栈底部的书编号为 ,所有书的数字都是不同的。
Vasya 想在 次操作下,把所有书都移动到他的背包里,在第 次操作中他想移动编号为 的书到他的包里,如果这本书还在栈中,他将取走 和 以上的所有书,并且将它们都放到包里,否则他什么都不需要做,并且开始取下一本书。
请你帮助 Vasya,告诉他每一步他要取走几本书。
翻译提供:@Maysoul
输入格式
第一行只有一个整数 ,代表栈中书的数量。
第二行有 个整数 表示栈中书的编号。
第三行有 个整数 表示 Vasya 将要取走的书。
保证 互不相同, 互不相同。
输出格式
输出 个整数,代表在第 步 Vasya 需要移动的书的数目,如不需移动则输出 。
数据范围
。
。
。
说明/提示
在样例 中,第一步 Vasya 取走了编号为 及以上的三本书,在那之后,只有编号为 和 的书还在栈中,并且 在 上面,在下一步 Vasya 取走了编号为 及以上的两本书,在之后的操作中,没有书可以再被移动了。
题目描述
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.
输入格式
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 .
输出格式
Print integers. The -th of them should be equal to the number of books Vasya moves to his backpack during the -th step.
输入输出样例
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
提示
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.