本地测了多组样例也过了?为什么WA?
查看原帖
本地测了多组样例也过了?为什么WA?
387926
8905suwenjie楼主2021/4/14 17:12
#include <bits/stdc++.h>
using namespace std;
int q,n;
int a[1000000],b[1000000];
stack<int>s;

int main(){
	cin>>q;
while(q--){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	int top=1;
	for(int i=1;i<=n;i++){
		s.push(a[i]);
		while(s.top()==b[top]){
			s.pop();
			top++;
			if(s.empty()){
				break;
			}
		}
	}
	if(s.empty()){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}
}
2021/4/14 17:12
加载中...