题目传送门

C++代码

#include<bits/stdc++.h>

using namespace std;
const int N = 100010;
int a[N], b[N];
int stk[N], tt;
int n, q;

//纯模拟算法
int main() {
    cin >> q;
    while (q--) {
        //清空栈
        tt = 0;

        //输入
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> a[i];
        for (int i = 1; i <= n; i++) cin >> b[i];

        int head = 1;
        for (int i = 1; i <= n; i++) {
            stk[++tt] = a[i];
            while (stk[tt] == b[head]) {
                tt--;
                head++;
                if (tt == 0) break;
            }
        }
        if (tt == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

相关文章:

  • 2022-12-23
  • 2021-06-05
  • 2021-09-24
  • 2021-06-20
  • 2021-12-16
  • 2021-07-21
  • 2022-12-23
猜你喜欢
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2022-02-23
  • 2021-10-16
相关资源
相似解决方案