rt,赛时写的唐解法。
洛谷 100 AC,不知 CCF 会不会给 5 pts
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,a[N],mp[N];
struct node{
int a,b,c;
};
bool operator >(node a,node b){
return a.a>b.a;
}
priority_queue<node,vector<node>,greater<node> >q,q2; // q 存 还活着的,q2 存还能打的
int main(){
// freopen("duel4.in","r",stdin);
// freopen("duel4.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
mp[a[i]]++;
}
for(int i=0;i<=200000;i++){
if(mp[i]){
q.emplace((node){i,mp[i],mp[i]});
q2.emplace((node){i,mp[i],mp[i]});
}
}
int ans=n;
while(q.size()>=2&&q2.size()){
node tp=q.top();
q.pop();
while(q2.top().a<=tp.a) q2.pop();
node tp2=q2.top();
q2.pop();
if(tp.c>tp2.b){
ans-=tp2.b;
node tmp={tp.a,tp.b,tp.c-tp2.b};
q.push(tmp);
}else{
ans-=tp.c;
node tmp={tp2.a,tp2.b-tp.c,tp2.c};
if(tmp.b) q2.push(tmp);
}
}
cout<<ans<<'\n';
return 0;
}