제출 #398599

#제출 시각아이디문제언어결과실행 시간메모리
398599mosiashvililuka다리 (APIO19_bridges)C++14
59 / 100
3070 ms5564 KiB
#include<bits/stdc++.h>
using namespace std;
const int T=450;
int a,b,c,d,e,i,j,ii,jj,zx,xc,tes,t,te,fx[100009],pi,msh[100009],sz[100009],cnt,bo[100009],ans[100009];
int qi,qqi;
int A,B,C,D,E;
stack <pair <int, int> > M,S;
pair <pair <int, int>, int> P[100009];
pair <int, pair <int, int> > Q[100009],p[100009];
pair <int, int> q[100009],qq[100009];
int fnd(int q){
	while(msh[q]!=0) q=msh[q];
	return q;
}
void mrg(int q, int w){
	q=fnd(q);w=fnd(w);
	if(q==w) return;
	if(sz[q]<sz[w]) swap(q,w);
	M.push(make_pair(w,msh[w]));
	S.push(make_pair(q,sz[q]));
	msh[w]=q;
	sz[q]+=sz[w];
}
void rollback(){
	msh[M.top().first]=M.top().second;
	sz[S.top().first]=S.top().second;
	M.pop();S.pop();
}
void ROLL(int q){
	while(M.size()>q){
		msh[M.top().first]=M.top().second;
		sz[S.top().first]=S.top().second;
		M.pop();S.pop();
	}
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>b;
	for(i=1; i<=b; i++){
		cin>>P[i].first.first>>P[i].first.second>>P[i].second;
		P[i].second=-P[i].second;
	}
	cin>>tes;
	for(t=1; t<=tes; t++){
		cin>>Q[t].first>>Q[t].second.first>>Q[t].second.second;
		Q[t].second.second=-Q[t].second.second;
	}
	for(t=1; t<=tes; t++){
		ans[t]=-1;
	}
	for(t=T; ; t+=T){
		te=t-T+1;
		if(t>tes) t=tes;
		if(te>t) break;
		pi=0;
		for(i=te; i<=t; i++){
			if(Q[i].first==1){
				fx[Q[i].second.first]=t;
			}
		}
		for(i=1; i<=a; i++){
			msh[i]=0;sz[i]=1;
		}
		while(M.size()) M.pop();
		while(S.size()) S.pop();
		/*for(i=te-1; i>=1; i--){
			if(Q[i].first==1){
				if(fx[Q[i].second.first]==t) continue;
				pi++;
				p[pi].first=Q[i].second.second;
				p[pi].second=P[Q[i].second.first].first;
				fx[Q[t].second.first]=t;
			}
		}*/
		for(i=1; i<=b; i++){
			if(fx[i]==t) continue;
			pi++;
			p[pi].first=P[i].second;
			p[pi].second=P[i].first;
		}
		sort(p+1,p+pi+1);
		qi=0;qqi=0;
		for(i=te; i<=t; i++){
			if(Q[i].first==1){
				
			}else{
				qqi++;
				qq[qqi].first=Q[i].second.second;
				qq[qqi].second=i;
			}
		}
		sort(qq+1,qq+qqi+1);
		A=1;B=1;
		for(i=1; i<=qqi; i++){
			while(A<=pi&&p[A].first<=qq[i].first){
				mrg(p[A].second.first,p[A].second.second);
				A++;
			}
			E=M.size();
			cnt++;
			for(j=qq[i].second; j>=te; j--){
				if(Q[j].first==2) continue;
				if(bo[Q[j].second.first]==cnt){
					
				}else{
					bo[Q[j].second.first]=cnt;
					if(Q[j].second.second<=qq[i].first){
						mrg(P[Q[j].second.first].first.first,P[Q[j].second.first].first.second);
					}
				}
			}
			for(j=qq[i].second+1; j<=t; j++){
				if(Q[j].first==1&&bo[Q[j].second.first]!=cnt){
					if(P[Q[j].second.first].second<=qq[i].first){
						mrg(P[Q[j].second.first].first.first,P[Q[j].second.first].first.second);
					}
					bo[Q[j].second.first]=cnt;
				}
			}
			c=Q[qq[i].second].second.first;d=qq[i].second;
			ans[d]=sz[fnd(c)];
			ROLL(E);
		}
		for(i=te; i<=t; i++){
			if(Q[i].first==1){
				P[Q[i].second.first].second=Q[i].second.second;
			}
		}
	}
	for(t=1; t<=tes; t++){
		if(ans[t]==-1) continue;
		cout<<ans[t]<<endl;
	}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp: In function 'void ROLL(int)':
bridges.cpp:30:16: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |  while(M.size()>q){
      |        ~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...