Submission #428465

# Submission time Handle Problem Language Result Execution time Memory
428465 2021-06-15T12:05:24 Z mosiashvililuka Inside information (BOI21_servers) C++14
7.5 / 100
433 ms 36164 KB
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,tes,t,msh[200009][19],dp[200009],lf[200009],rg[200009],tim,st[200009],shv[200009],dep[200009],f[200009],lc,E,C,D;
int fen1[200009],fen2[200009];
pair <char, pair <int, int> > p[1000009];
vector <int> v[200009];
void upd1(int q, int w){
	while(q<=200001){
		fen1[q]+=w;
		q=q+(q&(-q));
	}
}
int read1(int q){
	int sm=0;
	while(q>=1){
		sm+=fen1[q];
		q=q-(q&(-q));
	}
	return sm;
}
void upd2(int q, int w){
	while(q<=200001){
		fen2[q]+=w;
		q=q+(q&(-q));
	}
}
int read2(int q){
	int sm=0;
	while(q>=1){
		sm+=fen2[q];
		q=q-(q&(-q));
	}
	return sm;
}
bool anc(int q, int w){
	if(lf[q]<=lf[w]&&rg[w]<=rg[q]) return 1; else return 0;
}
int lca(int q, int w){
	if(anc(q,w)) return q;
	if(anc(w,q)) return w;
	for(int h=17; h>=0; h--){
		if(msh[q][h]!=0&&anc(msh[q][h],w)==0){
			q=msh[q][h];
		}
	}
	return msh[q][0];
}
int upto(int q, int w){
	for(int h=17; h>=0; h--){
		if(msh[q][h]!=0&&anc(msh[q][h],w)==0){
			q=msh[q][h];
		}
	}
	return q;
}
void dfsst(int q, int w){
	dep[q]=dep[w]+1;
	msh[q][0]=w;
	for(int h=1; h<=17; h++) msh[q][h]=msh[msh[q][h-1]][h-1];
	//tim++;lf[q]=rg[q]=tim;
	dp[q]=1;
	for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
		if((*it)==w) continue;
		dfsst((*it),q);
		dp[q]+=dp[(*it)];
		//if(rg[(*it)]>rg[q]) rg[q]=rg[(*it)];
	}
}
void dfs(int q, int w, bool BO){
	tim++;lf[q]=rg[q]=tim;
	if(BO==0){
		st[q]=q;
	}
	if(q!=1&&v[q].size()==1) return;
	if(v[q].size()==0) return;
	int MX=0;
	for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
		if((*it)==w) continue;
		if(dp[(*it)]>dp[MX]) MX=(*it);
	}
	shv[q]=MX;st[shv[q]]=st[q];
	dfs(shv[q],q,1);
	if(rg[MX]>rg[q]) rg[q]=rg[MX];
	for(vector <int>::iterator it=v[q].begin(); it!=v[q].end(); it++){
		if((*it)==w||(*it)==shv[q]) continue;
		dfs((*it),q,0);
		if(rg[(*it)]>rg[q]) rg[q]=rg[(*it)];
	}
}
void UP1(int q){
	if(anc(q,lc)) return;
	if(f[q]==-1){
		E=1;
		return;
	}
	int w=0;if(lf[st[q]]>lf[lc]) w=st[q]; else w=upto(q,lf[lc]);
	if(lf[q]-lf[w]<=0||lf[q]-lf[w]==read1(lf[q]-1)-read1(lf[w]-1)){
		
	}else{
		E=1;
		return;
	}
	if(msh[w][0]!=lc){
		if(f[msh[w][0]]==-1||f[msh[w][0]]>f[w]||f[w]==-1){
			E=1;
			return;
		}
	}
	UP1(msh[w][0]);
}
void UP2(int q){
	if(anc(q,lc)) return;
	if(f[q]==-1){
		E=1;
		return;
	}
	int w=0;if(lf[st[q]]>lf[lc]) w=st[q]; else w=upto(q,lf[lc]);
	//if(lf[q]-lf[w]==read2(lf[q])-read2(lf[w]-1)){
	if(lf[q]-lf[w]<=0||lf[q]-lf[w]==read2(lf[q]-1)-read2(lf[w]-1)){
		
	}else{
		E=1;
		return;
	}
	if(msh[w][0]!=lc){
		if(f[msh[w][0]]==-1||f[msh[w][0]]<f[w]||f[w]==-1){
			E=1;
			return;
		}
	}
	UP2(msh[w][0]);
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>tes;
	tes=tes+a-1;
	for(t=1; t<=tes; t++){
		cin>>p[t].first;
		if(p[t].first=='S'){
			cin>>p[t].second.first>>p[t].second.second;
			v[p[t].second.first].push_back(p[t].second.second);
			v[p[t].second.second].push_back(p[t].second.first);
		}
		if(p[t].first=='Q'){
			cin>>p[t].second.first>>p[t].second.second;
		}
		if(p[t].first=='C'){
			cin>>p[t].second.first;
		}
	}
	dfsst(1,0);
	dfs(1,0,0);
	for(i=1; i<=a; i++) f[i]=-1;
	/*for(i=1; i<=a; i++){
		cout<<lf[i]<<" "<<shv[i]<<" "<<st[i]<<endl;
	}*/
	for(t=1; t<=tes; t++){
		if(p[t].first=='S'){
			c=p[t].second.first;d=p[t].second.second;
			if(msh[c][0]==d) swap(c,d);
			f[d]=t;
			if(shv[d]!=0){
				if(f[shv[d]]!=-1){
					upd2(lf[d],1);
				}
			}
			if(st[d]!=d){
				if(f[c]!=-1){
					upd1(lf[c],1);
				}
			}
			continue;
		}
		if(p[t].first=='Q'){
			//cout<<read1(3)<<" "<<read1(1)<<endl;
			//return 0;
			d=p[t].second.first;c=p[t].second.second;
			E=0;
			lc=lca(c,d);
			UP1(d);UP2(c);
			if(c!=lc&&d!=lc){
				C=upto(c,lc);D=upto(d,lc);
				if(f[C]==-1||f[D]==-1||f[C]>f[D]) E=1;
			}
			if(E==0){
				cout<<"yes"<<endl;
			}else{
				cout<<"no"<<endl;
			}
			//return 0;
			continue;
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 225 ms 7748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 225 ms 7748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 228 ms 7740 KB Output is correct
2 Correct 347 ms 27156 KB Output is correct
3 Correct 362 ms 27200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 228 ms 7740 KB Output is correct
2 Correct 347 ms 27156 KB Output is correct
3 Correct 362 ms 27200 KB Output is correct
4 Incorrect 221 ms 7628 KB Extra information in the output file
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 226 ms 7772 KB Output is correct
2 Correct 426 ms 36024 KB Output is correct
3 Correct 416 ms 36068 KB Output is correct
4 Correct 394 ms 35524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 7772 KB Output is correct
2 Correct 426 ms 36024 KB Output is correct
3 Correct 416 ms 36068 KB Output is correct
4 Correct 394 ms 35524 KB Output is correct
5 Incorrect 206 ms 7760 KB Extra information in the output file
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 228 ms 7716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 228 ms 7716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 220 ms 7736 KB Output is correct
2 Correct 409 ms 36052 KB Output is correct
3 Correct 433 ms 36164 KB Output is correct
4 Correct 414 ms 35484 KB Output is correct
5 Incorrect 229 ms 7888 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 220 ms 7736 KB Output is correct
2 Correct 409 ms 36052 KB Output is correct
3 Correct 433 ms 36164 KB Output is correct
4 Correct 414 ms 35484 KB Output is correct
5 Incorrect 229 ms 7888 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 230 ms 7736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 230 ms 7736 KB Output isn't correct
2 Halted 0 ms 0 KB -