QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#19941#2214. Link Cut Digraphwxp#AC ✓496ms49336kbC++142.3kb2022-02-14 08:52:562022-05-08 01:39:33

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 01:39:33]
  • 评测
  • 测评结果:AC
  • 用时:496ms
  • 内存:49336kb
  • [2022-02-14 08:52:56]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define vep(i,x) for(int i=0;i<x.size();++i)
#define per(i,x,y) for(int i=x;i>=y;--i)
#define mar(o) for(int E=fst[o];E;E=e[E].nxt)
#define v e[E].to
#define lon long long
#define vi vector <int>
#define pb emplace_back
using namespace std;
const int n7=2012345,m7=10123456;
struct dino{int to,nxt;}e[m7];
int n,m,t,dfn[n7],low[n7],top,sak[n7],in[n7],col[n7],tim,colc;
int vis[n7],lad[n7],ep[n7],eq[n7],fa[n7],siz[n7],ecnt,fst[n7];
lon ans[n7];
vector <int> rab;

int rd(){
	int shu=0;bool fu=0;char ch=getchar();
	while( !isdigit(ch) ){if(ch=='-')fu=1;ch=getchar();}
	while( isdigit(ch) )shu=(shu<<1)+(shu<<3)+ch-'0',ch=getchar();
	return fu?-shu:shu;
}

void edge(int p,int q){
	int ecntz;
	if( rab.size() )ecntz=rab.back(),rab.pop_back();
	else ecnt++,ecntz=ecnt;
	e[ecntz]=(dino){q,fst[p]};
	fst[p]=ecntz;
}

void tarjan(int o){
	t++,dfn[o]=low[o]=t;
	top++,sak[top]=o,sak[top+1]=0,in[o]=1;
	mar(o){
		if(!dfn[v])tarjan(v),low[o]=min(low[o],low[v]);
		else if(in[v])low[o]=min(low[o],dfn[v]);
	}
	if(dfn[o]^low[o])return;
	colc++,lad[colc]=o;
	while(sak[top+1]^o){
		in[ sak[top] ]=0;
		col[ sak[top] ]=colc;
		top--;
	}
}

void clear(int o){
	mar(o)rab.pb(E);
	vis[o]=tim,fst[o]=dfn[o]=low[o]=0;
}

int getf(int z){
	while(z^fa[z])z=fa[z]=fa[ fa[z] ];
	return z;
}

void dopart(int l,int r,vi now){
	tim++;int mid=(l+r)>>1;
	vi nev;
	vep(i,now){
		if(now[i]>mid)continue;
		int d1=getf(ep[ now[i] ]),d2=getf(eq[ now[i] ]);
		if(vis[d1]^tim)clear(d1),nev.pb(d1);
		if(vis[d2]^tim)clear(d2),nev.pb(d2);
		edge(d1,d2);
	}
	vep(i,nev)if(!dfn[ nev[i] ])tarjan(nev[i]);
	if(l==r){
		vep(i,nev){
			int fa1=getf(nev[i]),fa2=getf(lad[ col[ nev[i] ] ]);
			if(fa1==fa2)continue;
			ans[l]=ans[l]+1ll*siz[fa1]*siz[fa2];
			fa[fa1]=fa2,siz[fa2]+=siz[fa1];
		}
	}
	else{
		vi nowl,nowr;
		vep(i,now){
			int d1=getf(ep[ now[i] ]),d2=getf(eq[ now[i] ]);
			if(vis[d1]==tim&&vis[d2]==tim&&col[d1]==col[d2])nowl.pb(now[i]);
			else nowr.pb(now[i]);
		}
		dopart(l,mid,nowl),dopart(mid+1,r,nowr);
	}
}

int main(){
	n=rd(),m=rd();
	rep(i,1,m)ep[i]=rd(),eq[i]=rd();
	rep(i,1,n)fa[i]=i,siz[i]=1;
	vi tmp;
	rep(i,1,m)tmp.pb(i);
	dopart(1,m,tmp);
	rep(i,1,m)ans[i]+=ans[i-1],printf("%lld\n",ans[i]);
	return 0;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 461ms
memory: 43020kb

Test #2:

score: 0
Accepted
time: 460ms
memory: 43148kb

Test #3:

score: 0
Accepted
time: 494ms
memory: 43104kb

Test #4:

score: 0
Accepted
time: 383ms
memory: 47856kb

Test #5:

score: 0
Accepted
time: 491ms
memory: 43340kb

Test #6:

score: 0
Accepted
time: 433ms
memory: 43296kb

Test #7:

score: 0
Accepted
time: 437ms
memory: 42268kb

Test #8:

score: 0
Accepted
time: 433ms
memory: 43436kb

Test #9:

score: 0
Accepted
time: 320ms
memory: 49132kb

Test #10:

score: 0
Accepted
time: 428ms
memory: 43904kb

Test #11:

score: 0
Accepted
time: 465ms
memory: 42800kb

Test #12:

score: 0
Accepted
time: 457ms
memory: 43108kb

Test #13:

score: 0
Accepted
time: 368ms
memory: 49336kb

Test #14:

score: 0
Accepted
time: 379ms
memory: 49248kb

Test #15:

score: 0
Accepted
time: 192ms
memory: 33680kb

Test #16:

score: 0
Accepted
time: 412ms
memory: 36812kb

Test #17:

score: 0
Accepted
time: 392ms
memory: 36456kb

Test #18:

score: 0
Accepted
time: 383ms
memory: 37440kb

Test #19:

score: 0
Accepted
time: 496ms
memory: 43840kb

Test #20:

score: 0
Accepted
time: 427ms
memory: 43736kb

Test #21:

score: 0
Accepted
time: 380ms
memory: 44084kb

Test #22:

score: 0
Accepted
time: 406ms
memory: 43832kb

Test #23:

score: 0
Accepted
time: 397ms
memory: 43724kb

Test #24:

score: 0
Accepted
time: 445ms
memory: 43684kb

Test #25:

score: 0
Accepted
time: 423ms
memory: 43924kb

Test #26:

score: 0
Accepted
time: 407ms
memory: 43060kb

Test #27:

score: 0
Accepted
time: 401ms
memory: 42024kb