codeforces 1073B. Vasya and Books

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<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
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<n;i++)
		{
			int x;
			scanf("%d",&x);
			a[x]=++k;
		}
		for(int i=0;i<n;i++) scanf("%d",&b[i]);
		int maxn=0;
		for(int i=0;i<n;i++)
		{
			if(a[b[i]]==maxn) cout<<1<<" ";
			else if(a[b[i]]>maxn)
			{
				cout<<a[b[i]]-maxn<<" ";
				maxn=a[b[i]];
			}
			else cout<<0<<" ";
		}
	}
}

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值