yuhaoran666 @ 2022-07-11 17:34:55
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
stack<int> tmp;
int in[N], out[N], t, n, cnt;
int main() {
cin >> t;
for (int x = 1; x <= t; x++) {
cin >> n;
cnt = 0;
for (int i = 0; i < n; i++) cin >> in[i];
for (int i = 0; i < n; i++) {
cin >> out[i];
if (cnt < out[i]) for (int j = cnt; j < out[i]; j++) tmp.push(in[j]), cnt++;
if (tmp.top() == out[i]) tmp.pop();
else break;
}
cout << (tmp.empty() ? "Yes\n":"No\n");
while (!tmp.empty()) tmp.pop();
}
return 0;
}
by tXX_F @ 2022-07-11 21:00:01
#include<bits/stdc++.h>
using namespace std;
stack<int> st;
int n;
int a[101];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
int t=1;
for(int i=1;i<=n;i++){
st.push(i);
while(!st.empty()){
if(st.top()==a[t]){
st.pop();
t++;
}
else
break;
}
}
if(st.empty())printf("YES\n");
else printf("NO\n");
return 0;
}
```cpp
//参考这个
by yuhaoran666 @ 2022-07-11 21:55:32
@Hacker_King 已