답안 #388859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388859 2021-04-13T08:05:12 Z huangqr Joker (BOI20_joker) C++14
49 / 100
2000 ms 42956 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],relcpy[lim];
 
struct xystate{
	ll x,parx,relx,rnkx;
	ll y,pary,rely,rnky;
	xystate(ll ix,ll iparx,ll irelx,ll irnkx,
	ll iy,ll ipary,ll irely,ll irnky){
		x=ix,parx=iparx,relx=irelx,rnkx=irnkx;
		y=iy,pary=ipary,rely=irely,rnky=irnky;
	}
};

vector<xystate>sv;
 
pl findset(ll par[],ll rel[],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 rel[],ll x,ll y){
	pl px=findset(par,rel,x),py=findset(par,rel,y);
	x=px.first,y=py.first;
	if(x==y)return;
	if(rnk[x]>rnk[y])swap(x,y);
	sv.push_back(xystate(x,par[x],rel[x],rnk[x],y,par[y],rel[y],rnk[y]));
	if(rnk[x]==rnk[y])rnk[y]++;
	par[x]=y;
	rnk[y]++;
	rel[x]=(px.second==py.second);
	return;
}

void rollback(ll until_sz){
	while(sv.size()>until_sz){
		xystate c=sv.back();
		par[c.x]=c.parx;
		rnk[c.x]=c.rnkx;
		rel[c.x]=c.relx;
		par[c.y]=c.pary;
		rnk[c.y]=c.rnky;
		rel[c.y]=c.rely;
		sv.pop_back();
	}
}
 
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--){
		sort(qs[i].begin(),qs[i].end());
		for(int i=1;i<=n;i++)parcpy[i]=par[i],rnkcpy[i]=rnk[i],relcpy[i]=rel[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,relcpy,v[cur].first),y=findset(parcpy,relcpy,v[cur].second);
				if(x.first==y.first){
				if(x.second==y.second){
					oddc=1;
				}
			}
				else mergeset(parcpy,rnkcpy,relcpy,v[cur].first,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,rel,v[i].first),y=findset(par,rel,v[i].second);
		if(x.first==y.first){
			if(x.second==y.second){
				cfa=1;
			}
		}
		else mergeset(par,rnk,rel,v[i].first,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],relcpy[i]=rel[i];
		ll cur=0,prevsz=sv.size();
		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(par,rel,v[cur].first),y=findset(par,rel,v[cur].second);
				if(x.first==y.first){
					if(x.second==y.second){
						oddc=1;
					}
				}
				else mergeset(par,rnk,rel,v[cur].first,v[cur].second);
			}
			ans[x.second]=oddc;
			
		}
		rollback(prevsz);
	}
	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 'pl findset(ll*, ll*, ll)':
Joker.cpp:23:11: warning: unused variable 'og' [-Wunused-variable]
   23 |  ll cur=0,og=x;
      |           ^~
Joker.cpp: In function 'void rollback(ll)':
Joker.cpp:47:17: warning: comparison of integer expressions of different signedness: 'std::vector<xystate>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   47 |  while(sv.size()>until_sz){
      |        ~~~~~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 3 ms 5196 KB Output is correct
4 Correct 4 ms 5196 KB Output is correct
5 Correct 3 ms 5196 KB Output is correct
6 Correct 4 ms 5196 KB Output is correct
7 Correct 5 ms 5188 KB Output is correct
8 Correct 5 ms 5376 KB Output is correct
9 Correct 4 ms 5196 KB Output is correct
10 Correct 4 ms 5196 KB Output is correct
11 Correct 5 ms 5196 KB Output is correct
12 Correct 4 ms 5324 KB Output is correct
13 Correct 4 ms 5200 KB Output is correct
14 Correct 4 ms 5324 KB Output is correct
15 Correct 4 ms 5324 KB Output is correct
16 Correct 4 ms 5324 KB Output is correct
17 Correct 4 ms 5196 KB Output is correct
18 Correct 4 ms 5196 KB Output is correct
19 Correct 4 ms 5196 KB Output is correct
20 Correct 4 ms 5196 KB Output is correct
21 Correct 4 ms 5196 KB Output is correct
22 Correct 4 ms 5196 KB Output is correct
23 Correct 4 ms 5196 KB Output is correct
24 Correct 4 ms 5196 KB Output is correct
25 Correct 4 ms 5196 KB Output is correct
26 Correct 4 ms 5168 KB Output is correct
27 Correct 4 ms 5196 KB Output is correct
28 Correct 4 ms 5196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 3 ms 5196 KB Output is correct
4 Correct 4 ms 5196 KB Output is correct
5 Correct 3 ms 5196 KB Output is correct
6 Correct 4 ms 5196 KB Output is correct
7 Correct 5 ms 5188 KB Output is correct
8 Correct 5 ms 5376 KB Output is correct
9 Correct 4 ms 5196 KB Output is correct
10 Correct 4 ms 5196 KB Output is correct
11 Correct 5 ms 5196 KB Output is correct
12 Correct 4 ms 5324 KB Output is correct
13 Correct 4 ms 5200 KB Output is correct
14 Correct 4 ms 5324 KB Output is correct
15 Correct 4 ms 5324 KB Output is correct
16 Correct 4 ms 5324 KB Output is correct
17 Correct 4 ms 5196 KB Output is correct
18 Correct 4 ms 5196 KB Output is correct
19 Correct 4 ms 5196 KB Output is correct
20 Correct 4 ms 5196 KB Output is correct
21 Correct 4 ms 5196 KB Output is correct
22 Correct 4 ms 5196 KB Output is correct
23 Correct 4 ms 5196 KB Output is correct
24 Correct 4 ms 5196 KB Output is correct
25 Correct 4 ms 5196 KB Output is correct
26 Correct 4 ms 5168 KB Output is correct
27 Correct 4 ms 5196 KB Output is correct
28 Correct 4 ms 5196 KB Output is correct
29 Correct 20 ms 5580 KB Output is correct
30 Correct 28 ms 5708 KB Output is correct
31 Correct 25 ms 5708 KB Output is correct
32 Correct 20 ms 5608 KB Output is correct
33 Correct 12 ms 5452 KB Output is correct
34 Correct 24 ms 5708 KB Output is correct
35 Correct 27 ms 5736 KB Output is correct
36 Correct 14 ms 5580 KB Output is correct
37 Correct 28 ms 5816 KB Output is correct
38 Correct 54 ms 5780 KB Output is correct
39 Correct 14 ms 5780 KB Output is correct
40 Correct 16 ms 5648 KB Output is correct
41 Correct 16 ms 5644 KB Output is correct
42 Correct 16 ms 5580 KB Output is correct
43 Correct 27 ms 5452 KB Output is correct
44 Correct 34 ms 5648 KB Output is correct
45 Correct 40 ms 5708 KB Output is correct
46 Correct 48 ms 5712 KB Output is correct
47 Correct 17 ms 5604 KB Output is correct
48 Correct 21 ms 5628 KB Output is correct
49 Correct 22 ms 5688 KB Output is correct
50 Correct 25 ms 5736 KB Output is correct
51 Correct 19 ms 5588 KB Output is correct
52 Correct 21 ms 5580 KB Output is correct
53 Correct 23 ms 5708 KB Output is correct
54 Correct 26 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 122 ms 29384 KB Output is correct
4 Correct 143 ms 38312 KB Output is correct
5 Correct 118 ms 24808 KB Output is correct
6 Correct 121 ms 25456 KB Output is correct
7 Correct 123 ms 25504 KB Output is correct
8 Correct 111 ms 21416 KB Output is correct
9 Correct 114 ms 25524 KB Output is correct
10 Correct 122 ms 30140 KB Output is correct
11 Correct 126 ms 25448 KB Output is correct
12 Correct 131 ms 29328 KB Output is correct
13 Correct 117 ms 17328 KB Output is correct
14 Correct 117 ms 21416 KB Output is correct
15 Correct 125 ms 27356 KB Output is correct
16 Correct 132 ms 30192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 3 ms 5196 KB Output is correct
4 Correct 4 ms 5196 KB Output is correct
5 Correct 3 ms 5196 KB Output is correct
6 Correct 4 ms 5196 KB Output is correct
7 Correct 5 ms 5188 KB Output is correct
8 Correct 5 ms 5376 KB Output is correct
9 Correct 4 ms 5196 KB Output is correct
10 Correct 4 ms 5196 KB Output is correct
11 Correct 5 ms 5196 KB Output is correct
12 Correct 4 ms 5324 KB Output is correct
13 Correct 4 ms 5200 KB Output is correct
14 Correct 4 ms 5324 KB Output is correct
15 Correct 4 ms 5324 KB Output is correct
16 Correct 4 ms 5324 KB Output is correct
17 Correct 4 ms 5196 KB Output is correct
18 Correct 4 ms 5196 KB Output is correct
19 Correct 4 ms 5196 KB Output is correct
20 Correct 4 ms 5196 KB Output is correct
21 Correct 4 ms 5196 KB Output is correct
22 Correct 4 ms 5196 KB Output is correct
23 Correct 4 ms 5196 KB Output is correct
24 Correct 4 ms 5196 KB Output is correct
25 Correct 4 ms 5196 KB Output is correct
26 Correct 4 ms 5168 KB Output is correct
27 Correct 4 ms 5196 KB Output is correct
28 Correct 4 ms 5196 KB Output is correct
29 Correct 122 ms 29384 KB Output is correct
30 Correct 143 ms 38312 KB Output is correct
31 Correct 118 ms 24808 KB Output is correct
32 Correct 121 ms 25456 KB Output is correct
33 Correct 123 ms 25504 KB Output is correct
34 Correct 111 ms 21416 KB Output is correct
35 Correct 114 ms 25524 KB Output is correct
36 Correct 122 ms 30140 KB Output is correct
37 Correct 126 ms 25448 KB Output is correct
38 Correct 131 ms 29328 KB Output is correct
39 Correct 117 ms 17328 KB Output is correct
40 Correct 117 ms 21416 KB Output is correct
41 Correct 125 ms 27356 KB Output is correct
42 Correct 132 ms 30192 KB Output is correct
43 Correct 407 ms 34264 KB Output is correct
44 Correct 388 ms 42956 KB Output is correct
45 Correct 327 ms 42740 KB Output is correct
46 Correct 191 ms 30356 KB Output is correct
47 Correct 219 ms 29992 KB Output is correct
48 Correct 266 ms 29920 KB Output is correct
49 Correct 245 ms 35176 KB Output is correct
50 Correct 200 ms 33296 KB Output is correct
51 Correct 216 ms 31880 KB Output is correct
52 Correct 228 ms 34512 KB Output is correct
53 Correct 173 ms 21472 KB Output is correct
54 Correct 219 ms 33276 KB Output is correct
55 Correct 256 ms 36216 KB Output is correct
56 Correct 268 ms 34520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 3 ms 5196 KB Output is correct
4 Correct 4 ms 5196 KB Output is correct
5 Correct 3 ms 5196 KB Output is correct
6 Correct 4 ms 5196 KB Output is correct
7 Correct 5 ms 5188 KB Output is correct
8 Correct 5 ms 5376 KB Output is correct
9 Correct 4 ms 5196 KB Output is correct
10 Correct 4 ms 5196 KB Output is correct
11 Correct 5 ms 5196 KB Output is correct
12 Correct 4 ms 5324 KB Output is correct
13 Correct 4 ms 5200 KB Output is correct
14 Correct 4 ms 5324 KB Output is correct
15 Correct 4 ms 5324 KB Output is correct
16 Correct 4 ms 5324 KB Output is correct
17 Correct 4 ms 5196 KB Output is correct
18 Correct 4 ms 5196 KB Output is correct
19 Correct 4 ms 5196 KB Output is correct
20 Correct 4 ms 5196 KB Output is correct
21 Correct 4 ms 5196 KB Output is correct
22 Correct 4 ms 5196 KB Output is correct
23 Correct 4 ms 5196 KB Output is correct
24 Correct 4 ms 5196 KB Output is correct
25 Correct 4 ms 5196 KB Output is correct
26 Correct 4 ms 5168 KB Output is correct
27 Correct 4 ms 5196 KB Output is correct
28 Correct 4 ms 5196 KB Output is correct
29 Correct 20 ms 5580 KB Output is correct
30 Correct 28 ms 5708 KB Output is correct
31 Correct 25 ms 5708 KB Output is correct
32 Correct 20 ms 5608 KB Output is correct
33 Correct 12 ms 5452 KB Output is correct
34 Correct 24 ms 5708 KB Output is correct
35 Correct 27 ms 5736 KB Output is correct
36 Correct 14 ms 5580 KB Output is correct
37 Correct 28 ms 5816 KB Output is correct
38 Correct 54 ms 5780 KB Output is correct
39 Correct 14 ms 5780 KB Output is correct
40 Correct 16 ms 5648 KB Output is correct
41 Correct 16 ms 5644 KB Output is correct
42 Correct 16 ms 5580 KB Output is correct
43 Correct 27 ms 5452 KB Output is correct
44 Correct 34 ms 5648 KB Output is correct
45 Correct 40 ms 5708 KB Output is correct
46 Correct 48 ms 5712 KB Output is correct
47 Correct 17 ms 5604 KB Output is correct
48 Correct 21 ms 5628 KB Output is correct
49 Correct 22 ms 5688 KB Output is correct
50 Correct 25 ms 5736 KB Output is correct
51 Correct 19 ms 5588 KB Output is correct
52 Correct 21 ms 5580 KB Output is correct
53 Correct 23 ms 5708 KB Output is correct
54 Correct 26 ms 5708 KB Output is correct
55 Execution timed out 2075 ms 28836 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5196 KB Output is correct
2 Correct 3 ms 5196 KB Output is correct
3 Correct 3 ms 5196 KB Output is correct
4 Correct 4 ms 5196 KB Output is correct
5 Correct 3 ms 5196 KB Output is correct
6 Correct 4 ms 5196 KB Output is correct
7 Correct 5 ms 5188 KB Output is correct
8 Correct 5 ms 5376 KB Output is correct
9 Correct 4 ms 5196 KB Output is correct
10 Correct 4 ms 5196 KB Output is correct
11 Correct 5 ms 5196 KB Output is correct
12 Correct 4 ms 5324 KB Output is correct
13 Correct 4 ms 5200 KB Output is correct
14 Correct 4 ms 5324 KB Output is correct
15 Correct 4 ms 5324 KB Output is correct
16 Correct 4 ms 5324 KB Output is correct
17 Correct 4 ms 5196 KB Output is correct
18 Correct 4 ms 5196 KB Output is correct
19 Correct 4 ms 5196 KB Output is correct
20 Correct 4 ms 5196 KB Output is correct
21 Correct 4 ms 5196 KB Output is correct
22 Correct 4 ms 5196 KB Output is correct
23 Correct 4 ms 5196 KB Output is correct
24 Correct 4 ms 5196 KB Output is correct
25 Correct 4 ms 5196 KB Output is correct
26 Correct 4 ms 5168 KB Output is correct
27 Correct 4 ms 5196 KB Output is correct
28 Correct 4 ms 5196 KB Output is correct
29 Correct 20 ms 5580 KB Output is correct
30 Correct 28 ms 5708 KB Output is correct
31 Correct 25 ms 5708 KB Output is correct
32 Correct 20 ms 5608 KB Output is correct
33 Correct 12 ms 5452 KB Output is correct
34 Correct 24 ms 5708 KB Output is correct
35 Correct 27 ms 5736 KB Output is correct
36 Correct 14 ms 5580 KB Output is correct
37 Correct 28 ms 5816 KB Output is correct
38 Correct 54 ms 5780 KB Output is correct
39 Correct 14 ms 5780 KB Output is correct
40 Correct 16 ms 5648 KB Output is correct
41 Correct 16 ms 5644 KB Output is correct
42 Correct 16 ms 5580 KB Output is correct
43 Correct 27 ms 5452 KB Output is correct
44 Correct 34 ms 5648 KB Output is correct
45 Correct 40 ms 5708 KB Output is correct
46 Correct 48 ms 5712 KB Output is correct
47 Correct 17 ms 5604 KB Output is correct
48 Correct 21 ms 5628 KB Output is correct
49 Correct 22 ms 5688 KB Output is correct
50 Correct 25 ms 5736 KB Output is correct
51 Correct 19 ms 5588 KB Output is correct
52 Correct 21 ms 5580 KB Output is correct
53 Correct 23 ms 5708 KB Output is correct
54 Correct 26 ms 5708 KB Output is correct
55 Correct 122 ms 29384 KB Output is correct
56 Correct 143 ms 38312 KB Output is correct
57 Correct 118 ms 24808 KB Output is correct
58 Correct 121 ms 25456 KB Output is correct
59 Correct 123 ms 25504 KB Output is correct
60 Correct 111 ms 21416 KB Output is correct
61 Correct 114 ms 25524 KB Output is correct
62 Correct 122 ms 30140 KB Output is correct
63 Correct 126 ms 25448 KB Output is correct
64 Correct 131 ms 29328 KB Output is correct
65 Correct 117 ms 17328 KB Output is correct
66 Correct 117 ms 21416 KB Output is correct
67 Correct 125 ms 27356 KB Output is correct
68 Correct 132 ms 30192 KB Output is correct
69 Correct 407 ms 34264 KB Output is correct
70 Correct 388 ms 42956 KB Output is correct
71 Correct 327 ms 42740 KB Output is correct
72 Correct 191 ms 30356 KB Output is correct
73 Correct 219 ms 29992 KB Output is correct
74 Correct 266 ms 29920 KB Output is correct
75 Correct 245 ms 35176 KB Output is correct
76 Correct 200 ms 33296 KB Output is correct
77 Correct 216 ms 31880 KB Output is correct
78 Correct 228 ms 34512 KB Output is correct
79 Correct 173 ms 21472 KB Output is correct
80 Correct 219 ms 33276 KB Output is correct
81 Correct 256 ms 36216 KB Output is correct
82 Correct 268 ms 34520 KB Output is correct
83 Execution timed out 2075 ms 28836 KB Time limit exceeded
84 Halted 0 ms 0 KB -