标签:std priority freopen cpp uva string cassert reg struct
极似UVa11995 I Can Guess the Data Structure!
模拟即可,时间复杂度(……)\(O(n \log n)\)
旁边的L君:这题有两个坑点,我被卡了一次。
然而我一次就AC了。
旁边的L君:一个坑点是空栈,一个是输出格式
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<complex>
#include<cassert>
#define rg register
#define il inline
#define co const
#pragma GCC optimize ("O0")
using namespace std;
template<class T> il T read()
{
T data=0;
int w=1;
char ch=getchar();
while(!isdigit(ch))
{
if(ch==‘-‘)
w=-1;
ch=getchar();
}
while(isdigit(ch))
data=10*data+ch-‘0‘,ch=getchar();
return data*w;
}
template<class T> il T read(T&x)
{
return x=read<T>();
}
typedef long long ll;
const int INF=0x7fffffff;
stack<int>S;
queue<int>Q;
priority_queue<int>H;
int main()
{
freopen("qu.in","r",stdin);
freopen("qu.out","w",stdout);
int n=read<int>();
bool is=1,iq=1,ih=1;
for(int i=1;i<=n;++i)
{
int opt=read<int>(),v=read<int>();
if(opt==1)
{
if(is)
{
S.push(v);
}
if(iq)
{
Q.push(v);
}
if(ih)
{
H.push(v);
}
}
else
{
if(is)
{
if(S.empty())
is=0;
else if(S.top()!=v)
is=0;
else
S.pop();
}
if(iq)
{
if(Q.empty())
iq=0;
else if(Q.front()!=v)
iq=0;
else
Q.pop();
}
if(ih)
{
if(H.empty())
ih=0;
else if(H.top()!=v)
ih=0;
else
H.pop();
}
}
}
printf("%s\n",is?"YES":"No");
printf("%s\n",iq?"YES":"No");
printf("%s\n",ih?"YES":"No");
// fclose(stdin);
// fclose(stdout);
return 0;
}
标签:std priority freopen cpp uva string cassert reg struct
原文地址:https://www.cnblogs.com/autoint/p/9845741.html