周赛0507A题题解
public
May 09, 2025
Never
19
1 #include<bits/stdc++.h> 2 using namespace std; 3 priority_queue<int,vector<int>,greater<int> > q;//在线排序 4 int ch(){//查看有几个序列使用了当前数 5 int now=q.top(); 6 int u=1; 7 q.pop(); 8 while((!q.empty())&&q.top()==now){ 9 ++u; 10 q.pop(); 11 } 12 return u; 13 } 14 int main(){ 15 16 ios::sync_with_stdio(NULL); 17 cin.tie(nullptr);cout.tie(nullptr); 18 int t;cin>>t; 19 while(t--){ 20 int n;cin>>n; 21 for(int i=1;i<=n;++i){ 22 int r;cin>>r; 23 q.push(r); 24 } 25 int ans=0; 26 int last=0; 27 int lastis=-1; 28 while(!q.empty()){ 29 int tp=q.top(); 30 if(lastis+1<tp)last=0;//判断与前一个数能否拼序列 31 int cnt=ch(); 32 if(last<cnt)ans+=(cnt-last);//如果包含序列开头,序列数加差 33 last=cnt; 34 lastis=tp; 35 } 36 cout<<ans<<endl; 37 } 38 return 0; 39 }