0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 06:51:58 +00:00

P4387 【深基15.习9】验证栈序列

R43140011
This commit is contained in:
Baoshuo Ren 2020-12-04 07:13:19 +08:00 committed by Baoshuo Ren
parent 0962fb88c1
commit 5b24a25a0f
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

31
problem/P4387/P4387.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
int n, s = 1, a[100005], b[100005];
stack<int> st;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
for (int i = 1; i <= n; i++) {
st.push(a[i]);
while (!st.empty() && st.top() == b[s]) {
st.pop();
s++;
}
}
if (st.empty())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}