QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#18318#2214. Link Cut DigraphwxpAC ✓493ms48972kbC++142.3kb2022-01-17 17:34:002022-05-04 17:55:41

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-04 17:55:41]
  • 评测
  • 测评结果:AC
  • 用时:493ms
  • 内存:48972kb
  • [2022-01-17 17:34:00]
  • 提交

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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 405ms
memory: 35636kb

Test #2:

score: 0
Accepted
time: 421ms
memory: 36408kb

Test #3:

score: 0
Accepted
time: 424ms
memory: 37036kb

Test #4:

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

Test #5:

score: 0
Accepted
time: 394ms
memory: 38072kb

Test #6:

score: 0
Accepted
time: 443ms
memory: 40028kb

Test #7:

score: 0
Accepted
time: 418ms
memory: 39600kb

Test #8:

score: 0
Accepted
time: 422ms
memory: 40168kb

Test #9:

score: 0
Accepted
time: 339ms
memory: 47172kb

Test #10:

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

Test #11:

score: 0
Accepted
time: 448ms
memory: 40752kb

Test #12:

score: 0
Accepted
time: 493ms
memory: 41792kb

Test #13:

score: 0
Accepted
time: 359ms
memory: 47548kb

Test #14:

score: 0
Accepted
time: 363ms
memory: 48972kb

Test #15:

score: 0
Accepted
time: 182ms
memory: 33256kb

Test #16:

score: 0
Accepted
time: 394ms
memory: 36516kb

Test #17:

score: 0
Accepted
time: 381ms
memory: 37108kb

Test #18:

score: 0
Accepted
time: 390ms
memory: 37288kb

Test #19:

score: 0
Accepted
time: 426ms
memory: 43240kb

Test #20:

score: 0
Accepted
time: 387ms
memory: 45656kb

Test #21:

score: 0
Accepted
time: 389ms
memory: 45796kb

Test #22:

score: 0
Accepted
time: 393ms
memory: 46032kb

Test #23:

score: 0
Accepted
time: 382ms
memory: 45524kb

Test #24:

score: 0
Accepted
time: 378ms
memory: 45432kb

Test #25:

score: 0
Accepted
time: 372ms
memory: 45464kb

Test #26:

score: 0
Accepted
time: 385ms
memory: 44544kb

Test #27:

score: 0
Accepted
time: 395ms
memory: 43416kb