luxize1022 @ 2024-09-16 21:56:11
为什么WA了???
#include<bits/stdc++.h>
using namespace std;
long long m,n,t,b[100005],a[100005];
stack<int>q;
int main(){
cin>>n;
while(n--){
while(!q.empty())q.pop();
cin>>m;
for(int i=1;i<=m;i++){
cin>>a[i];
}
for(int j=1;j<=m;j++){
cin>>b[j];
}
long long j=1;
q.push(0);
for(int i=1;i<=m;i++){
if(a[i]==b[j]){
j++;
}
else if(q.top()==b[j]){
while(!q.empty()&&(b[j]==q.top())){
q.pop();
j++;
}
}
else{
q.push(a[i]);
}
}
while(!q.empty()&&(b[j]==q.top())){
q.pop();
j++;
}
if(j<=m){
cout<<"No"<<endl;
}
else {
cout<<"Yes"<<endl;
}
}
return 0;
}
by PeppaYang @ 2024-09-16 22:07:52
你做过车厢调度吗?
by NIKEAJ @ 2024-09-16 22:12:39
格式化一下吧 @luxize1022