Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
30448 | liuyile | 【S】T3 | C++ | 解答错误 | 0 | 1133 MS | 372256 KB | 1986 | 2024-07-19 15:43:46 |
#include <bits/stdc++.h> // #pragma GCC optimize("Ofast,unroll-loops,inline") using namespace std; // #pragma GCC optimize(3) // #define int long long #define endl "\n" char buf[1<<20], *p1, *p2; inline char gc() { if (p1 == p2) { p1 = buf; p2 = buf + fread(buf, 1, 1<<20, stdin); if (p1 == p2) return EOF; } return *p1++; } int n; int a[2100300]; vector<int>g[2100300]; vector<int>loc[2100300]; vector<int>w[2100300]; const int N=(1<<20)-1; const int LG=20; int dfn[2100300],low[2100300]; int tp; int tk=0,cnt=0; int bel[2100300]; int S[2100300]; int hd[2100000]; bool inst[2100000],vis[2100000]; struct node{int v,nxt;}E[1000030*20+2000000]; int ec=0; inline void ins(int u,int v){ ++ec; E[ec]={v,hd[u]}; hd[u]=ec; } inline void mn(int &x,int y){ if(x>y)x=y; } inline void dfs(int &u){ dfn[u]=low[u]=++tk; S[++tp]=u; inst[u]=vis[u]=1; for(int i=hd[u];i;i=E[i].nxt){ int v=E[i].v; if(!vis[v])dfs(v),mn(low[u],low[v]); else if(inst[v])mn(low[u],dfn[v]); } if(dfn[u]==low[u]){ ++cnt; while(tp){ int x=S[tp]; tp--; inst[x]=0; bel[x]=cnt; if(x==u)break; } } } #define idg(x) (x>='0'&&x<='9') inline int rd(){ int x=0,w=gc(); while(!idg(w))w=gc(); while(idg(w))x=x*10+w-'0',w=gc(); return x; } signed main(){ ios::sync_with_stdio(0); // freopen("seq.in","r",stdin); // freopen("seq.out","w",stdout); for(int i=1;i<=N;i++) for(int j=0;j<LG;j++) if((i>>j)&1) ins(i,i^(1<<j)); n=rd(); for(int i=1;i<=n;i++) a[i]=rd(); for(int i=1;i<=n;i++) ins(i+N,N^a[i]),ins(a[i],N+i); int p=N; dfs(p); for(int i=1;i<=n;i++) loc[bel[i+N]].emplace_back(i), w[bel[i+N]].emplace_back(a[i]); return 0; for(int i=1;i<=cnt;i++){ sort(w[i].begin(),w[i].end()); int k=loc[i].size(); for(int j=0;j<k;j++) a[loc[i][j]]=w[i][j]; } for(int i=1;i<=n;i++) printf("%d ",a[i]); cout.flush(); return 0; }