From 5b24a25a0fb561e6338ab50927fd4bb7f8488fe6 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Fri, 4 Dec 2020 07:13:19 +0800 Subject: [PATCH] =?UTF-8?q?P4387=20=E3=80=90=E6=B7=B1=E5=9F=BA15.=E4=B9=A0?= =?UTF-8?q?9=E3=80=91=E9=AA=8C=E8=AF=81=E6=A0=88=E5=BA=8F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R43140011 --- problem/P4387/P4387.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 problem/P4387/P4387.cpp diff --git a/problem/P4387/P4387.cpp b/problem/P4387/P4387.cpp new file mode 100644 index 00000000..3c7c7d9f --- /dev/null +++ b/problem/P4387/P4387.cpp @@ -0,0 +1,31 @@ +#include + +using namespace std; + +int main() { + int q; + cin >> q; + while (q--) { + int n, s = 1, a[100005], b[100005]; + stack 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; +}