0分wa,样例过了求助
查看原帖
0分wa,样例过了求助
1313312
zzdkf20081224楼主2024/8/9 10:29
using namespace std;
int q,n,a[100005],b[100005];
stack<int> m;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>q;
	for(int i=1;i<=q;i++){
		int top=1;
		cin>>n;
		for(int j=1;j<=n;j++){
			cin>>a[j];
		}
		for(int j=1;j<=n;j++){
			cin>>b[j];
		}
		while(!m.empty()) m.pop();
		for(int j=1;j<=n;j++){
			m.push(a[j]);
			while(!m.empty()&&b[top]==m.top()){//在这里加empty()防止数组越界 
				top++;
				m.pop();
			}
			
		}
		if(m.empty()) cout<<"YES"<<"\n";
		else cout<<"NO"<<"\n";
	}
	return 0;
}
2024/8/9 10:29
加载中...