其他帖子爆0的样例我都能过,但是还是爆0
#include <bits/stdc++.h>
using namespace std;
int up[100100];
queue<int> qu;//下边的
stack<int> s; //上边入栈的
bool judge(){ //判断剩下的是否一一对应
while(!qu.empty()){
if(qu.front()!=s.top()){
return false;
}
qu.pop();
s.pop();
}
return true;
}
int main()
{
int n; cin>>n;
while(n--){
int nx;
cin>>nx;
for(int i=1;i<=nx;i++){ //上边暂存
cin>>up[i];
}
int nnx=nx;
while(nnx--){ //下边入队
int y;
cin>>y;
qu.push(y);
}
for(int i=1;i<=nx;i++){ //上边入栈
while((!s.empty())&&(s.top()==qu.front())){
s.pop();
qu.pop();
}
s.push(up[i]);
if(s.top()==qu.front()){
s.pop();
qu.pop();
}
}
bool res=judge(); //判断剩下的元素是否一一对应
//清空栈和队列
while(!qu.empty()){
qu.pop();
}
while(!s.empty()){
s.pop();
}
//输出
if(res){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
return 0;
}