Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
30388 liuyile 【S】T4 C++ 解答错误 0 729 MS 324284 KB 1336 2024-07-19 12:42:55

Tests(0/20):


#include <bits/stdc++.h> using namespace std; // #define int long long #define endl "\n" int n; int a[2000300]; vector<int>g[3000300]; vector<int>loc[3000300]; vector<int>w[3000300]; const int N=(1<<20)-1; const int LG=20; int dfn[3000300],low[3000300]; stack<int>S; int tk=0,cnt=0; int bel[3000300]; inline void dfs(int u){ dfn[u]=low[u]=++tk; S.push(u); for(int v:g[u]) if(!dfn[v])dfs(v),low[u]=min(low[u],low[v]); else if(!bel[v])low[u]=min(low[u],dfn[v]); if(dfn[u]==low[u]){ ++cnt; while(!S.empty()){ int x=S.top(); S.pop(); bel[x]=cnt; if(x==u)break; } } } 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) g[i].push_back(i^(1<<j)); scanf("%d ",&n); for(int i=1;i<=n;i++) scanf("%d" ,&a[i]); for(int i=1;i<=n;i++) g[i+N].push_back(N^a[i]),g[a[i]].push_back(N+i); dfs(N); return 0 ; for(int i=1;i<=n;i++) loc[bel[i+N]].push_back(i), w[bel[i+N]].push_back(a[i]); for(int i=1;i<=cnt;i++){ sort(loc[i].begin(),loc[i].end()); 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; }


测评信息: