Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
30622 | yuanjiabao | 【S】T3 | C++ | 运行出错 | 0 | 1642 MS | 371364 KB | 1688 | 2024-07-20 14:18:50 |
#include<iostream> #include<algorithm> #include<vector> #include<cstring> #include<ctime> #include<vector> #define timeMS (clock()*1000/CLOCKS_PER_SEC) int clk=0; using namespace std; const int N=1000100,LG=20,V=(1<<LG)+N,E=2*N+LG*(1<<LG),msk=(1<<LG)-1; vector<int>g[V]; int ver; inline void insert(int u,int v){g[u].emplace_back(v);} int n,a[N]; int stk[V],top; bool in_stk[V]; int low[V],dfn[V]; int bel[V]; int tot; void init(){ memset(bel,-1,sizeof(bel)); cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++)insert(i+msk,a[i]),insert(a[i]^msk,i+msk); for(int i=1;i<=msk;i++){ for(int j=0;j<LG;j++)if(i&(1<<j))insert(i^(1<<j),i); } ver=msk+n; } void tarjan(int nd){ dfn[nd]=low[nd]=++tot; stk[++top]=nd; in_stk[nd]=true; for(int nx:g[nd])if(bel[nx]<0){ if(in_stk[nx])low[nd]=min(low[nd],dfn[nx]); else tarjan(nx),low[nd]=min(low[nd],low[nx]); } if(low[nd]==dfn[nd]){ while(stk[top]!=nd)in_stk[stk[top]]=false,bel[stk[top--]]=nd; in_stk[stk[top]]=false,bel[stk[top--]]=nd; } } vector<int>blk[V]; int p[V]; bool vis[V]; int main(){ // freopen("seq.in","r",stdin); // freopen("seq.out","w",stdout); init(); for(int i=0;i<=ver;i++)if(bel[i]<0)tarjan(i); for(int i=1;i<=n;i++)blk[bel[i+msk]].emplace_back(a[i]); clk-=timeMS; for(int i=1;i<=n;i++)if(!vis[bel[i+msk]])vis[bel[i+msk]]=true,sort(blk[bel[i+msk]].begin(),blk[bel[i+msk]].end()); clk+=timeMS; for(int i=1;i<=n;i++)a[i]=blk[bel[i+msk]][p[bel[i+msk]]++]; for(int i=1;i<=n;i++)cout<<a[i]<<' '; // cerr<<timeMS; return 0; }