70TLE求调
查看原帖
70TLE求调
1268907
uncle_steve楼主2025/7/28 12:12

map 存内容,set 排序

#include<bits/stdc++.h>
using namespace std;
map<int,string>mp;
set<int>s;
int n,m,a[500001];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        s.insert(a[i]);
        if(mp[a[i]]!="") mp[a[i]]="";
        set<int>::iterator it=s.begin();
        for(it;it!=s.end();it++){
            mp[a[i]]+=to_string(*it);
            mp[a[i]]+=" ";
        } 
    }
    for(int i=1;i<=m;i++){
        cout<<mp[i].size()-1<<" ";
    }

    return 0;
}
2025/7/28 12:12
加载中...