80pts 基础并查集悬关求助
查看原帖
80pts 基础并查集悬关求助
654958
Light_az楼主2023/3/16 17:18
#include<bits/stdc++.h>
#define ll long long
#define F(i,j,n) for(int i=j;i<=n;i++)
#define Tr(v,e) for(int v:e)
#define Test ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
using namespace std;
const int N=1e7+10,NN=1e4+10;
ll n,m,k,x,y,u,v,w,cnt=0,ans=0,t=0,l,r,len,T,num,mid;
ll mini=INT_MAX,maxi=0,Mod;
string s1,s2;
ll a[N],f[N];
map<ll,ll> mp;
ll find(ll x){
	if(x==f[x]) return x;
	return f[x]=find(f[x]);
}
int main(){
	cin>>n;
	F(i,1,n) f[i]=i;
	F(i,1,n){
		cin>>x;
		if(!mp[x]){
			cout<<x<<" ";
			mp[x]=1;
			f[x]=find(x+1);
		}
		else{
			x=find(x);
			cout<<x<<" ";
			mp[x]=1;
			f[x]=find(x+1);
		}
	}
	
	return 0;
}

2023/3/16 17:18
加载中...