社区讨论
问了ai也找不出哪里re了,求调
P4387【深基15.习9】验证栈序列参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mk415sfs
- 此快照首次捕获于
- 2026/01/07 21:04 2 个月前
- 此快照最后确认于
- 2026/01/10 18:25 2 个月前
CPP
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
using namespace std;
const int mod = 1e9 + 7;
//#define int long long
#define fo(i,a,n) for(int i=a;i<=n;i++)
int n, a, m;
bool is[100005];
void solve()
{
queue<int>temp;
cin >> n;
fo(i, 1, n) { cin >> a; temp.push(a); }
stack<int>r;
while (n--)
{
cin >> a;
if (is[a])
{
if (r.empty()||r.top() == a) { r.pop(); }
else { cout << "No" << endl; return; }
}
else
{
while (!is[a])
{
if(temp.empty()){break;}
is[temp.front()] = true;
r.push(temp.front()); temp.pop();
}
r.pop();
}
}
cout << "Yes" << endl;
fo(i,1,100000){is[i]=false;}
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int _;
_ = 1;
cin >> _;
while (_--)
{
solve();
}
return 0;
}
//检查数组大小
//检查数组方括号内的内容
//检查l会不会写成1
/*
inline int read() >>读入优化
{
int x=0; char ch=getchar();
while (ch<'0' || ch>'9') ch=getchar();
while (ch>='0' && ch<='9')
{
x=(x<<3)+(x<<1)+ch-48; ch=getchar();
}
return x;
}
inline void write(int x) >>输出优化
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
*/
回复
共 3 条回复,欢迎继续交流。
正在加载回复...