help!!!
查看原帖
help!!!
663693
chenjieyang楼主2022/11/14 21:18
//P1160 队列安排
#include<iostream>
#include<algorithm>
#include<stack>
#define ll long long 
using namespace std;
ll q,n,a[100010],b[100010];
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];
        }
        bool flag=1;
        stack<ll>s;
        ll cnt=1;
        for(int i=1;i<=n;i++){
            s.push(a[i]);
            while(s.top()==b[cnt]){
                cnt++;
                s.pop();
            }
        }
        if(s.empty()){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}
2022/11/14 21:18
加载中...