【一句话题意】给定入队序列,求字典序最大的出队序列。
【分析】显然,这是一道模拟题;显然,满足字典序最大,贪心即可。
然后喷一下出题人,没有设置
Θ
(
n
)
\Theta(n)
Θ(n)的点,
Θ
(
n
l
o
g
2
n
)
∗
S
T
L
\Theta(nlog_2n)*STL
Θ(nlog2n)∗STL乱搞也可以轻松卡过。
【code】
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=2e5+100;
int n,a[maxn],mx[maxn];
int s[maxn],top;
inline void read(int &x){
x=0;int fl=1;char tmp=getchar();
while(tmp<'0'||tmp>'9') {if(tmp=='-')fl=-fl;tmp=getchar();}
while(tmp>='0'&&tmp<='9') x=(x<<1)+(x<<3)+tmp-'0',tmp=getchar();
x=x*fl;
}
int main(){
freopen("seq.in","r",stdin);
freopen("seq.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++) read(a[i]);
for(int i=n;i>=1;i--) mx[i]=max(mx[i+1],a[i]);
for(int i=1;i<=n;i++){
if(!top) s[++top]=a[i];
else{
while(top>0&&s[top]>mx[i])printf("%d ",s[top--]);
s[++top]=a[i];
}
}
while(top>0) printf("%d ",s[top--]);
return 0;
}