最大序列 seq.cpp

31 篇文章 0 订阅
10 篇文章 0 订阅

【一句话题意】给定入队序列,求字典序最大的出队序列。

【分析】显然,这是一道模拟题;显然,满足字典序最大,贪心即可。
然后喷一下出题人,没有设置 Θ ( 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值