博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces 1073B. Vasya and Books
阅读量:4136 次
发布时间:2019-05-25

本文共 2586 字,大约阅读时间需要 8 分钟。

B. Vasya and Books

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Vasya has got nn books, numbered from 11 to nn, arranged in a stack. The topmost book has number a1a1, the next one — a2a2, and so on. The book at the bottom of the stack has number anan. All numbers are distinct.

Vasya wants to move all the books to his backpack in nn steps. During ii-th step he wants to move the book number bibi into his backpack. If the book with number bibi is in the stack, he takes this book and all the books above the book bibi, and puts them into the backpack; otherwise he does nothing and begins the next step. For example, if books are arranged in the order [1,2,3][1,2,3] (book 11 is the topmost), and Vasya moves the books in the order [2,1,3][2,1,3], then during the first step he will move two books (11 and 22), during the second step he will do nothing (since book 11 is already in the backpack), and during the third step — one book (the book number 33). Note that b1,b2,…,bnb1,b2,…,bn 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 n (1≤n≤2⋅105)n (1≤n≤2⋅105) — the number of books in the stack.

The second line contains nn integers a1,a2,…,an (1≤ai≤n)a1,a2,…,an (1≤ai≤n) denoting the stack of books.

The third line contains nn integers b1,b2,…,bn (1≤bi≤n)b1,b2,…,bn (1≤bi≤n) denoting the steps Vasya is going to perform.

All numbers a1…ana1…an are distinct, the same goes for b1…bnb1…bn.

Output

Print nn integers. The ii-th of them should be equal to the number of books Vasya moves to his backpack during the ii-th step.

Examples

inputCopy
3
1 2 3
2 1 3
outputCopy
2 0 1
inputCopy
5
3 1 4 2 5
4 5 1 3 2
outputCopy
3 2 0 0 0
inputCopy
6
6 5 4 3 2 1
6 5 3 4 2 1
outputCopy
1 1 2 0 1 1
Note
The first example is described in the statement.

In the second example, during the first step Vasya will move the books [3,1,4][3,1,4]. After that only books 22 and 55 remain in the stack (22 is above 55). During the second step Vasya will take the books 22 and 55. After that the stack becomes empty, so during next steps Vasya won’t move any books.

题目挺简单的一道题,直接上代码:

#include
#include
#include
#include
#include
using namespace std;const int maxx=2e5+10;int a[maxx];int b[maxx];int n;int main(){ while(scanf("%d",&n)!=EOF) { memset(a,0,sizeof(a)); int k=0; for(int i=0;i
maxn) { cout<
<<" "; maxn=a[b[i]]; } else cout<<0<<" "; } }}

努力加油a啊,(o)/~

转载地址:http://azxvi.baihongyu.com/

你可能感兴趣的文章
判断一个整数是否是回文数
查看>>
经典shell面试题整理
查看>>
腾讯的一道面试题—不用除法求数字乘积
查看>>
素数算法
查看>>
java多线程环境单例模式实现详解
查看>>
将一个数插入到有序的数列中,插入后的数列仍然有序
查看>>
在有序的数列中查找某数,若该数在此数列中,则输出它所在的位置,否则输出no found
查看>>
万年历
查看>>
作为码农你希望面试官当场指出你错误么?有面试官这样遭到投诉!
查看>>
好多程序员都认为写ppt是很虚的技能,可事实真的是这样么?
查看>>
如果按照代码行数发薪水会怎样?码农:我能刷到公司破产!
查看>>
程序员失误造成服务停用3小时,只得到半月辞退补偿,发帖喊冤
查看>>
码农:很多人称我“技术”,感觉这是不尊重!纠正无果后果断辞职
查看>>
php程序员看过来,这老外是在吐糟你吗?看看你中了几点!
查看>>
为什么说程序员是“培训班出来的”就是鄙视呢?
查看>>
码农吐糟同事:写代码低调点不行么?空格回车键与你有仇吗?
查看>>
阿里p8程序员四年提交6000次代码的确有功,但一次错误让人唏嘘!
查看>>
一道技术问题引起的遐想,最后得出结论技术的本质是多么的朴实!
查看>>
985硕士:非科班自学编程感觉还不如培训班出来的,硕士白读了?
查看>>
你准备写代码到多少岁?程序员们是这么回答的!
查看>>