1个AC,4个RE,求助
查看原帖
1个AC,4个RE,求助
324004
绿茶tevi楼主2024/11/26 14:31
#include<bits/stdc++.h>
using namespace std;
int main(){
	int q;
	cin>>q;
	for(int i=1;i<=q;i++){
		int n;
		cin>>n;
		vector<int>num;//数据是否入栈 
        vector<int>a(n+1,0);//pushed序列
        stack<int>b;
		for(int j=1;j<=n;j++){
			cin>>a[j];//读入pushed 
			if(num.size()<a[j]+1)num.resize(a[j]+1);  
			num[a[j]]=0;
		}
		int t=0;//储存pushed序列中入栈了几个元素 
		for(int j=1;j<=n;j++){
			int pu;
			cin>>pu;
			if(num[pu]==0){//该数据未入栈 
				if(b.empty()){//空栈,先存第一个数据再进行下面的循环(保证栈不为空) 
					t++;
					b.push(a[t]);
					num[a[t]]=1;
				}
				while(b.top()!=pu&&!b.empty()){//开始入栈,直到栈头为pu 
					t++;
					b.push(a[t]);
					num[a[t]]=1;
				}
			}
			if(num[pu]==1){//该数据已经入栈 
				if(b.top()==pu){//该数据为栈头 
					b.pop();//弹出 
					num[pu]=0;
				}
				else{
					cout<<"No"<<endl;//不符合序列 
					break;
				}
			}
			if(j==n)cout<<"Yes"<<endl;//poped序列检测完毕 
		}
	}
	return 0;
} 
2024/11/26 14:31
加载中...