Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
30527 yuanjiabao 【S】T3 C++ 运行超时 18 1519 MS 261796 KB 1749 2024-07-19 16:40:35

Tests(2/11):


#include<iostream> #include<algorithm> #include<vector> #include<cstring> using namespace std; inline int read(){ int i=getchar(),r=0; while(i<'0'||i>'9')i=getchar(); while(i>='0'&&i<='9')r=(r<<1)+(r<<3)+(i^48),i=getchar(); return r; } const int N=1000100,LG=20,V=(1<<LG)+N,E=2*N+LG*(1<<LG),msk=(1<<LG)-1; int head[V],to[E],nex[E],edge,ver; inline void insert(int u,int v){ edge++; to[edge]=v; nex[edge]=head[u]; head[u]=edge; } 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++)a[i]=read(); 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 i=head[nd];i;i=nex[i])if(bel[to[i]]<0){ if(in_stk[to[i]])low[nd]=min(low[nd],dfn[to[i]]); else tarjan(to[i]),low[nd]=min(low[nd],low[to[i]]); } 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]; 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]); // for(int i=1;i<=n;i++)sort(blk[bel[i+msk]].begin(),blk[bel[i+msk]].end()); // for(int i=1;i<=n;i++)a[i]=blk[bel[i+msk]][p[bel[i+msk]]++]; for(int i=1;i<=n;i++)printf("%d ",a[i]); return 0; }


测评信息: