Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
30585 | masppy | 【S】T3 | C++ | 通过 | 100 | 978 MS | 312284 KB | 2164 | 2024-07-19 21:06:14 |
#include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=2e6+2000; const int maxm=(1<<20)-1; int n,m,t,k,cnt=0,tot=0,root,tot1=0; int belong[maxn],a[maxn],dfn[maxn],low[maxn],vis[maxn],head[maxn]; int stk[maxn],tp=0; vector<int> location[maxn],value[maxn]; struct node{ int to,next; }edge[20000000]; 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; } void print(int x,int fg){ if(x>9) print(x/10,0); putchar((x%10)|0x30); if(fg) printf(" "); return; } void dfs(int pos){ dfn[pos]=low[pos]=++tot; stk[++tp]=pos; for(int i=head[pos];i!=0;i=edge[i].next){ //cout<<i<<endl; //cout<<pos<<" "<<i<<endl; int v=edge[i].to; //cout<<pos<<" "<<v<<endl; 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(tp>0){ ll y=stk[tp]; tp--; belong[y]=cnt; if(y==pos) return; } } // cout<<pos<<" "<<tp<<endl; } void add(int u,int v){ edge[++tot1].to=v; edge[tot1].next=head[u]; head[u]=tot1; } int main(){ // freopen("seq.in","r",stdin); // freopen("seq.out","w",stdout); memset(head,0,sizeof(head)); n=read(); for(register int i=1;i<=n;i++){ a[i]=read(); } for(register int i=1;i<=maxm;i++){ for(int j=0;j<20;j++){ if((i>>j)&1){ add(i,(i^(1<<j))); } } } for(register int i=1;i<=n;i++){ add(a[i],(a[i]^maxm)); } // cout<<tot1<<endl; dfs(maxm); for(register int i=1;i<=n;i++){ location[belong[a[i]]].push_back(i); value[belong[a[i]]].push_back(a[i]); } for(register int 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(register int j=0;j<siz;j++){ a[location[i][j]]=value[i][j]; } } for(register int i=1;i<=n;i+=2){ print(a[i],1); if(i<n) print(a[i+1],1); } //fclose(stdin); // fclose(stdout); return 0; }