D题求救!怎么也查不出错!

#include<bits/stdc++.h>
using namespace std;
int a[200010];
int main()
{
int ;
scanf(“%d”,&
);
while (_–)
{
int n;
scanf(“%d”,&n);
stackst;
for (int i=1;i<=n;i++)
{
scanf(“%d”,&a[i]);
if ((!st.empty())&&st.top()==a[i])
{
st.pop();
}
else
{
st.push(a[i]);
}
}
if (st.size()<=1)
{
int fff=1;
if (!st.empty()) st.pop();
int tmp=-1;
for (int i=1;i<=n;i++)
{
if ((!st.empty())&&st.top()==a[i])
{
st.pop();
if (st.empty())
{
tmp=-1;
}
}
else
{
st.push(a[i]);
if (tmp==-1)
{
tmp=a[i];
continue;
}
if (a[i]>tmp)
{
fff=0;
break;
}
tmp=a[i];
}
}
if (fff) printf(“YES\n”);
else printf(“nO\n”);
}
else
{
printf(“nO\n”);
}
}
return 0;
}

6 个赞

无语,说不完

4 个赞