Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
30554 | masppy | 【S】T3 | C++ | 运行超时 | 45 | 1000 MS | 109648 KB | 947 | 2024-07-19 18:45:16 |
#include<bits/stdc++.h> #define ll long long using namespace std; const ll maxn=1e6+300; const ll maxm=(1<<20)-1; ll n,m,t,k,cnt=0,tot=0,root; ll fa[maxn],a[maxn]; map<int,int> mp[maxn]; stack<ll> stk; vector<ll> q[2000300]; int find_root(int x){ if(fa[x]==x) return x; return fa[x]=find_root(fa[x]); } int main(){ //freopen("seq.in","r",stdin); // freopen("seq.out","w",stdout); scanf("%lld",&n); for(ll i=1ll;i<=n;i++){ scanf("%lld",&a[i]); fa[i]=i; } for(int i=1;i<=n;i++){ for(int j=1;j<i;j++){ if((a[i]&a[j])==0){ int fi=find_root(i),fj=find_root(j); if(fi!=fj) fa[fi]=fj; } } } for(int i=1;i<=n;i++){ mp[find_root(i)][a[i]]++; } for(int i=1;i<=n;i++){ auto it=mp[find_root(i)].begin(); printf("%lld ",(*it).first); (*it).second--; if(!(*it).second) mp[find_root(i)].erase(it); } //fclose(stdin); // fclose(stdout); return 0; }