CF187A 题解

发布时间 2023-12-21 21:24:43作者: shimingxin1007

原题传送门


题目大意

如题意翻译。

思路分析

很水的一道题目,可以将第一个排列 \(a\) 看作最终排列,接下来每输入一个数,让它与 \(a_m\) 进行比较,直到两个排列相同。

最后看题目范围,\(1≤n≤2\times10^5\),时间复杂度 \(\mathcal{O(n)}\),空间复杂度 \(\mathcal{O(n)}\)

代码:

/*Written by smx*/
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main() 
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m=1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		int t;
		cin>>t;
		if(a[m]==t)
		{
			m++;
		}
	}
	cout<<n-m+1;
	return 0;
}