关于可重集
查看原帖
关于可重集
1226952
Cosine_Func楼主2024/10/26 21:25

据说 multiset 常数很大?会不会被卡常?

#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define endl '\n'
#define itn int
#define pi pair<int,int>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
//#define int ll
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int N=1e5+5;
itn n,r;
multiset<int> st;
inline void Solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>r;
		st.insert(r);
	}
	for(auto i=st.begin();i!=st.end();i++){
		auto j=st.lower_bound((*i)-1);
		if(j!=st.begin() and *j==*i)j--;
		if(j!=st.end() and *j<*i)st.erase(j);
	}
	cout<<st.size();
}
signed main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);
    int T=1;
    //cin>>T;
    while(T--)
    	Solve();
    return 0;
}

2024/10/26 21:25
加载中...