Submission #388850

# Submission time Handle Problem Language Result Execution time Memory
388850 2021-04-13T07:23:30 Z huangqr Joker (BOI20_joker) C++14
0 / 100
2000 ms 17288 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<ll,pl> ppl;
const ll lim=2e5+5;
ll par[lim],rnk[lim],rel[lim];
ll parcpy[lim],rnkcpy[lim];

pl findset(ll par[],ll x){
	ll cur=0,og=x;
	while(x!=par[x]){
		if(rel[x])cur=1-cur;
		x=par[x];
	}
	par[og]=x;
	rel[og]=cur;
	return {x,cur};
}

void mergeset(ll par[],ll rnk[],ll x,ll y){
	pl px=findset(par,x),py=findset(par,y);
	x=px.first,y=py.first;
	if(x==y)return;
	if(rnk[x]>rnk[y])swap(x,y);
	if(rnk[x]==rnk[y])rnk[y]++;
	par[x]=y;
	rnk[y]++;
	rel[x]=(px.second==py.second);
	return;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(NULL);
	ll n,m,q;
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)par[i]=i;
	vector<pl>v;
	vector<pl>qs[lim];
	for(int i=0;i<m;i++){
		ll a,b;
		cin>>a>>b;
		v.emplace_back(a,b);
	}	
	//v.emplace_back(0,0);
	bool ans[lim],cfa=0;
	fill(ans,ans+lim,0);
	for(int i=0;i<q;i++){
		ll a,b;
		cin>>a>>b;
		b--,b++;//b is the minimum index that can be used on the right side
		qs[b].emplace_back(a,i);
	}
	for(int i=m;i>=m;i--){
		ll cur=0;
		bool oddc=0;
		sort(qs[i].begin(),qs[i].end());
		for(int i=1;i<=n;i++)parcpy[i]=par[i],rnkcpy[i]=rnk[i];
		for(auto x:qs[i]){
			if(oddc==1){
				ans[x.second]=1;
				continue;
			}
			for(;cur+1<x.first;cur++){
				pl x=findset(parcpy,v[cur].first),y=findset(parcpy,v[cur].second);
				if(x.first==y.first){
				if(x.second==y.second){
					oddc=1;
				}
			}
				else mergeset(parcpy,rnkcpy,v[cur].first,v[cur].second);
				pl resx=findset(parcpy,v[cur].first),resy=findset(parcpy,v[cur].second);			
			}
			ans[x.second]=oddc;
			
		}
	}
	
	for(int i=m-1;i>=1;i--){
		if(cfa==1){
			for(auto x:qs[i])ans[x.second]=1;
			continue;
		}
		pl x=findset(par,v[i].first),y=findset(par,v[i].second);
		if(x.first==y.first){
			if(x.second==y.second){
				cfa=1;
			}
		}
		else mergeset(par,rnk,v[i].first,v[i].second);
		pl resx=findset(par,v[i].first),resy=findset(par,v[i].second);

		if(qs[i].empty())continue;
		if(cfa==1){
			for(auto x:qs[i])ans[x.second]=1;
			continue;
		}
		
		sort(qs[i].begin(),qs[i].end());
		for(int i=1;i<=n;i++)parcpy[i]=par[i],rnkcpy[i]=rnk[i];
		ll cur=0;
		bool oddc=0;
		for(auto x:qs[i]){
			if(oddc==1){
				ans[x.second]=1;
				continue;
			}
			for(;cur+1<x.first;cur++){
				pl x=findset(parcpy,v[cur].first),y=findset(parcpy,v[cur].second);
				if(x.first==y.first){
				if(x.second==y.second){
					oddc=1;
				}
			}
				else mergeset(parcpy,rnkcpy,v[cur].first,v[cur].second);
				pl resx=findset(parcpy,v[cur].first),resy=findset(parcpy,v[cur].second);			
			}
			ans[x.second]=oddc;
			
		}
	}
	for(int i=0;i<q;i++){
		if(ans[i])cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:72:8: warning: variable 'resx' set but not used [-Wunused-but-set-variable]
   72 |     pl resx=findset(parcpy,v[cur].first),resy=findset(parcpy,v[cur].second);
      |        ^~~~
Joker.cpp:72:42: warning: variable 'resy' set but not used [-Wunused-but-set-variable]
   72 |     pl resx=findset(parcpy,v[cur].first),resy=findset(parcpy,v[cur].second);
      |                                          ^~~~
Joker.cpp:116:8: warning: variable 'resx' set but not used [-Wunused-but-set-variable]
  116 |     pl resx=findset(parcpy,v[cur].first),resy=findset(parcpy,v[cur].second);
      |        ^~~~
Joker.cpp:116:42: warning: variable 'resy' set but not used [-Wunused-but-set-variable]
  116 |     pl resx=findset(parcpy,v[cur].first),resy=findset(parcpy,v[cur].second);
      |                                          ^~~~
Joker.cpp:91:6: warning: variable 'resx' set but not used [-Wunused-but-set-variable]
   91 |   pl resx=findset(par,v[i].first),resy=findset(par,v[i].second);
      |      ^~~~
Joker.cpp:91:35: warning: variable 'resy' set but not used [-Wunused-but-set-variable]
   91 |   pl resx=findset(par,v[i].first),resy=findset(par,v[i].second);
      |                                   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 4 ms 5196 KB Output is correct
4 Correct 3 ms 5196 KB Output is correct
5 Correct 4 ms 5196 KB Output is correct
6 Incorrect 3 ms 5196 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 4 ms 5196 KB Output is correct
4 Correct 3 ms 5196 KB Output is correct
5 Correct 4 ms 5196 KB Output is correct
6 Incorrect 3 ms 5196 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Execution timed out 2074 ms 17288 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 4 ms 5196 KB Output is correct
4 Correct 3 ms 5196 KB Output is correct
5 Correct 4 ms 5196 KB Output is correct
6 Incorrect 3 ms 5196 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 4 ms 5196 KB Output is correct
4 Correct 3 ms 5196 KB Output is correct
5 Correct 4 ms 5196 KB Output is correct
6 Incorrect 3 ms 5196 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 4 ms 5196 KB Output is correct
4 Correct 3 ms 5196 KB Output is correct
5 Correct 4 ms 5196 KB Output is correct
6 Incorrect 3 ms 5196 KB Output isn't correct
7 Halted 0 ms 0 KB -