就模拟栈的进出过程
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
int a[100002];
int main()
{
int n;
while(scanf("%d",&n) != EOF)
{
stack<int >st1;
for(int i=0;i<n;++i)
{
scanf("%d",&a[i]);
}
int index = 0;
for(int i=0;i<n;++i)
{
int val;
scanf("%d",&val);
if((st1.empty() || st1.top() != val) && index<n)
{
while(a[index] != val && index < n)
{
st1.push(a[index++]);
}
index++;
}
else if(st1.top() == val)
{
st1.pop();
}
}
if(st1.empty())
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
return 0;
}