1 solutions
-
0
#include<bits/stdc++.h> using namespace std; int t,n,pushed[100010],poped[100010],p; int main(){ cin>>t; for(int i=0;i<t;i++){ p=0; stack<int>st; bool f=true; cin>>n; for(int j=0;j<n;j++) cin >> pushed[j]; for(int j=0;j<n;j++) cin >> poped[j]; for(int j=0;j<n;j++) { while(p<n&&(st.empty()||st.top()!=poped[j]))st.push(pushed[p++]); if(st.empty()||st.top()!=poped[j]) { f=false; break; } st.pop(); } cout<<(f?"Yes":"No")<<endl; } return 0; }
- 1
Information
- ID
- 1154
- Time
- 1000ms
- Memory
- 125MiB
- Difficulty
- 9
- Tags
- # Submissions
- 146
- Accepted
- 11
- Uploaded By