1023: 巨人排队

使用了set
set具有互异性,multiset没有
set和ordered_map都是使用erase和insert,find删插查。
使用clear清空

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
multiset<ll> que;
int main(){
	while(scanf("%d",&n)!=EOF){
		que.clear();
		que.insert(30010);
		ll ans=1;
		for(int i=1;i<=n;i++){
			ll h;
			scanf("%lld",&h);
			bool flag=0;
			auto it=que.lower_bound(h);
			if(it!=que.end()){
				if(*it>h){
					que.erase(*it);
					que.insert(h);
					flag=1;
					continue;
				}else if(*it==h){
					flag=1;
					continue;
				}
			}
			if(!flag){
				que.insert(h);
				ans++;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}
posted @ 2026-03-15 20:04  peter_shen  阅读(1)  评论(0)    收藏  举报