Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
30572 masppy 【S】T3 C++ 运行超时 54 1404 MS 445848 KB 1891 2024-07-19 19:36:33

Tests(6/11):


#include<bits/stdc++.h> #define ll long long using namespace std; const ll maxn=1e6+2000; const ll maxm=(1<<20)-1; ll n,m,t,k,cnt=0,tot=0,root; ll belong[2100300],a[1100300],dfn[2100300],low[2100300],h[2100300],vis[2100300]; stack<ll> stk; vector<ll> q[2100300],location[2100300],value[2100300]; inline int read() { int x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();} return x*f; } inline void dfs(ll pos){ dfn[pos]=low[pos]=++tot; stk.push(pos); ll siz=q[pos].size(); for(ll i=0;i<siz;i++){ //cout<<pos<<" "<<i<<endl; ll v=q[pos][i]; if(!dfn[v]){ dfs(v); low[pos]=min(low[pos],low[v]); } else if(!belong[v]){ low[pos]=min(low[pos],dfn[v]); } } if(dfn[pos]==low[pos]){ cnt++; while(!stk.empty()){ ll y=stk.top(); stk.pop(); belong[y]=cnt; if(y==pos) return; } } } inline void edge(ll tmp,int x){ if(vis[tmp]==x) return; vis[tmp]=x; for(ll j=0;j<20;j++){ if((tmp>>j)&1) q[tmp].push_back(tmp^(1<<j)),edge(tmp^(1<<j),10); } } int main(){ //freopen("seq.in","r",stdin); //freopen("seq.out","w",stdout); n=read(); for(ll i=1;i<=n;i++){ a[i]=read(); } for(ll i=1;i<=n;i++){ if(h[a[i]]) continue; h[a[i]]=1; q[a[i]].push_back(a[i]^maxm); q[maxm].push_back(a[i]); ll tmp=a[i]^maxm; edge(tmp,10); } dfs(maxm); for(ll i=1;i<=n;i++){ location[belong[a[i]]].push_back(i); value[belong[a[i]]].push_back(a[i]); } for(ll i=1;i<=cnt;i++){ sort(location[i].begin(),location[i].end()); sort(value[i].begin(),value[i].end()); ll siz=location[i].size(); for(ll j=0;j<siz;j++){ a[location[i][j]]=value[i][j]; } } for(ll i=1;i<=n;i++) printf("%lld ",a[i]); //fclose(stdin); // fclose(stdout); return 0; }


测评信息: