답안 #893175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893175 2023-12-26T15:34:15 Z amirhoseinfar1385 Joker (BOI20_joker) C++17
100 / 100
119 ms 6768 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
const unsigned int maxn=200000+10;
unsigned int n,m,q,dp[maxn],f;
pair<unsigned int,unsigned int>alle[maxn];

struct dsu{
	vector<unsigned int>ha;
	unsigned int par[maxn],sz[maxn];
	unsigned char val[maxn];
	dsu(){
		for(unsigned int i=0;i<maxn;i++){
			par[i]=i;
			sz[i]=1;
		}
	}
	unsigned int root(unsigned int u){
		while(u!=par[u]){
			u=par[u];
		}
		return u;
	}
	unsigned char len(unsigned int u){
		unsigned int ret=0;
		while(u!=par[u]){
			ret+=val[u];
			u=par[u];
		}
		return ret;
	}

	void con(unsigned int u,unsigned int v){
		unsigned int rootu=root(u),rootv=root(v);
		if(rootu!=rootv){
			if(sz[rootu]<sz[rootv]){
				swap(rootu,rootv);
				swap(u,v);
			}
			unsigned char lu=len(u),lv=len(v);
			par[rootv]=rootu;
			sz[rootu]+=sz[rootv];
			if((lu&1)==(lv&1)){
				val[rootv]=1;
			}
			else{
				val[rootv]=0;
			}
			ha.push_back(rootv);
			return ;
		}
		ha.push_back(0);
	}
	bool two(unsigned int u,unsigned int v){
		unsigned int rootu=root(u),rootv=root(v);
		if(rootu!=rootv){
			return 0;
		}
		unsigned char  lu=len(u),lv=len(v);
		if((lu&1)==(lv&1)){
			return 1;
		}
		return 0;
	}
	void back(){
		if((unsigned int)ha.back()==0){
			ha.pop_back();
			return ;
		}
		unsigned int x=ha.back();
		sz[par[x]]-=sz[x];
		par[x]=x;
		val[x]=0;
		ha.pop_back();
		return ;
	}
}ds;

void solve(unsigned int l,unsigned int r,unsigned int tl,unsigned int tr){
	if(l>r){
		return ;
	}
	if(tl==tr){
		for(unsigned int i=l;i<=r;i++){
			dp[i]=tl;
		}
		return ;
	}
	unsigned int opt=0;
	unsigned int now=ds.ha.size();
	unsigned int mid=(l+r)>>1;
	for(unsigned int i=l;i<=mid;i++){
		ds.con(alle[i].first,alle[i].second);
	}
	for(unsigned int i=tr;i>=tl;i--){
		if(ds.two(alle[i].first,alle[i].second)){
			opt=i;
			break;
		}
		ds.con(alle[i].first,alle[i].second);
	}
	dp[mid]=opt;
	while((unsigned int)ds.ha.size()>now){
		ds.back();
	}
	for(unsigned int i=l;i<=mid;i++){
		ds.con(alle[i].first,alle[i].second);
	}
	solve(mid+1,r,opt,tr);
	while((unsigned int)ds.ha.size()>now){
		ds.back();
	}
	for(unsigned int i=tr;i>opt;i--){
		ds.con(alle[i].first,alle[i].second);
	}
	solve(l,mid-1,tl,opt);
	while((unsigned int)ds.ha.size()>now){
		ds.back();
	}
}

unsigned int pre(){
	for(unsigned int i=1;i<=m;i++){
		if(ds.two(alle[i].first,alle[i].second)){
			return i;
		}
		ds.con(alle[i].first,alle[i].second);
	}
	return m+1;
}

unsigned int suf(){
	for(unsigned int i=m;i>=0;i--){
		if(ds.two(alle[i].first,alle[i].second)){
			return i;
		}
		ds.con(alle[i].first,alle[i].second);
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);	
	cin>>n>>m>>q;
	for(unsigned int i=1;i<=m;i++){
		cin>>alle[i].first>>alle[i].second;
	}
	unsigned int ind=pre();
	while((unsigned int)ds.ha.size()>0){
		ds.back();
	}
	solve(1,ind-1,0,m);
	for(unsigned int i=ind;i<=m;i++){
		dp[i]=m+2;
	}
	if((unsigned int)ds.ha.size()!=0){
		assert(0);
	}
	dp[0]=suf();
	for(unsigned int i=0;i<q;i++){
		unsigned int l,r;
		cin>>l>>r;
		if(dp[l-1]<=r){
			cout<<"NO\n";
		}
		else{
			cout<<"YES\n";
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2484 KB Output is correct
49 Correct 2 ms 2904 KB Output is correct
50 Correct 1 ms 2648 KB Output is correct
51 Correct 1 ms 2652 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 90 ms 5480 KB Output is correct
4 Correct 112 ms 6700 KB Output is correct
5 Correct 62 ms 6056 KB Output is correct
6 Correct 65 ms 5540 KB Output is correct
7 Correct 64 ms 5656 KB Output is correct
8 Correct 86 ms 5760 KB Output is correct
9 Correct 87 ms 5604 KB Output is correct
10 Correct 109 ms 5840 KB Output is correct
11 Correct 89 ms 5584 KB Output is correct
12 Correct 93 ms 5836 KB Output is correct
13 Correct 87 ms 5580 KB Output is correct
14 Correct 91 ms 5588 KB Output is correct
15 Correct 104 ms 5668 KB Output is correct
16 Correct 111 ms 5536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 90 ms 5480 KB Output is correct
30 Correct 112 ms 6700 KB Output is correct
31 Correct 62 ms 6056 KB Output is correct
32 Correct 65 ms 5540 KB Output is correct
33 Correct 64 ms 5656 KB Output is correct
34 Correct 86 ms 5760 KB Output is correct
35 Correct 87 ms 5604 KB Output is correct
36 Correct 109 ms 5840 KB Output is correct
37 Correct 89 ms 5584 KB Output is correct
38 Correct 93 ms 5836 KB Output is correct
39 Correct 87 ms 5580 KB Output is correct
40 Correct 91 ms 5588 KB Output is correct
41 Correct 104 ms 5668 KB Output is correct
42 Correct 111 ms 5536 KB Output is correct
43 Correct 89 ms 5588 KB Output is correct
44 Correct 117 ms 6768 KB Output is correct
45 Correct 111 ms 5848 KB Output is correct
46 Correct 62 ms 5588 KB Output is correct
47 Correct 68 ms 5588 KB Output is correct
48 Correct 91 ms 5844 KB Output is correct
49 Correct 115 ms 5840 KB Output is correct
50 Correct 92 ms 5584 KB Output is correct
51 Correct 96 ms 5516 KB Output is correct
52 Correct 97 ms 6012 KB Output is correct
53 Correct 87 ms 5528 KB Output is correct
54 Correct 94 ms 5704 KB Output is correct
55 Correct 105 ms 5680 KB Output is correct
56 Correct 110 ms 5620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2484 KB Output is correct
49 Correct 2 ms 2904 KB Output is correct
50 Correct 1 ms 2648 KB Output is correct
51 Correct 1 ms 2652 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 65 ms 5068 KB Output is correct
56 Correct 91 ms 6088 KB Output is correct
57 Correct 39 ms 5324 KB Output is correct
58 Correct 39 ms 4848 KB Output is correct
59 Correct 69 ms 4856 KB Output is correct
60 Correct 96 ms 5092 KB Output is correct
61 Correct 73 ms 5064 KB Output is correct
62 Correct 82 ms 5028 KB Output is correct
63 Correct 60 ms 5076 KB Output is correct
64 Correct 78 ms 5084 KB Output is correct
65 Correct 89 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 0 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 2 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2904 KB Output is correct
41 Correct 1 ms 2652 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 1 ms 2652 KB Output is correct
44 Correct 1 ms 2652 KB Output is correct
45 Correct 1 ms 2652 KB Output is correct
46 Correct 1 ms 2652 KB Output is correct
47 Correct 1 ms 2652 KB Output is correct
48 Correct 1 ms 2484 KB Output is correct
49 Correct 2 ms 2904 KB Output is correct
50 Correct 1 ms 2648 KB Output is correct
51 Correct 1 ms 2652 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 90 ms 5480 KB Output is correct
56 Correct 112 ms 6700 KB Output is correct
57 Correct 62 ms 6056 KB Output is correct
58 Correct 65 ms 5540 KB Output is correct
59 Correct 64 ms 5656 KB Output is correct
60 Correct 86 ms 5760 KB Output is correct
61 Correct 87 ms 5604 KB Output is correct
62 Correct 109 ms 5840 KB Output is correct
63 Correct 89 ms 5584 KB Output is correct
64 Correct 93 ms 5836 KB Output is correct
65 Correct 87 ms 5580 KB Output is correct
66 Correct 91 ms 5588 KB Output is correct
67 Correct 104 ms 5668 KB Output is correct
68 Correct 111 ms 5536 KB Output is correct
69 Correct 89 ms 5588 KB Output is correct
70 Correct 117 ms 6768 KB Output is correct
71 Correct 111 ms 5848 KB Output is correct
72 Correct 62 ms 5588 KB Output is correct
73 Correct 68 ms 5588 KB Output is correct
74 Correct 91 ms 5844 KB Output is correct
75 Correct 115 ms 5840 KB Output is correct
76 Correct 92 ms 5584 KB Output is correct
77 Correct 96 ms 5516 KB Output is correct
78 Correct 97 ms 6012 KB Output is correct
79 Correct 87 ms 5528 KB Output is correct
80 Correct 94 ms 5704 KB Output is correct
81 Correct 105 ms 5680 KB Output is correct
82 Correct 110 ms 5620 KB Output is correct
83 Correct 65 ms 5068 KB Output is correct
84 Correct 91 ms 6088 KB Output is correct
85 Correct 39 ms 5324 KB Output is correct
86 Correct 39 ms 4848 KB Output is correct
87 Correct 69 ms 4856 KB Output is correct
88 Correct 96 ms 5092 KB Output is correct
89 Correct 73 ms 5064 KB Output is correct
90 Correct 82 ms 5028 KB Output is correct
91 Correct 60 ms 5076 KB Output is correct
92 Correct 78 ms 5084 KB Output is correct
93 Correct 89 ms 5072 KB Output is correct
94 Correct 92 ms 5776 KB Output is correct
95 Correct 119 ms 6000 KB Output is correct
96 Correct 67 ms 5848 KB Output is correct
97 Correct 65 ms 5840 KB Output is correct
98 Correct 67 ms 5588 KB Output is correct
99 Correct 86 ms 5840 KB Output is correct
100 Correct 89 ms 5824 KB Output is correct
101 Correct 93 ms 5668 KB Output is correct
102 Correct 101 ms 5748 KB Output is correct
103 Correct 112 ms 5724 KB Output is correct
104 Correct 87 ms 5588 KB Output is correct
105 Correct 102 ms 5588 KB Output is correct
106 Correct 115 ms 5588 KB Output is correct
107 Correct 53 ms 6004 KB Output is correct
108 Correct 94 ms 5588 KB Output is correct
109 Correct 91 ms 5584 KB Output is correct
110 Correct 90 ms 5700 KB Output is correct
111 Correct 91 ms 5588 KB Output is correct
112 Correct 90 ms 5584 KB Output is correct
113 Correct 90 ms 5620 KB Output is correct
114 Correct 91 ms 5568 KB Output is correct
115 Correct 91 ms 5592 KB Output is correct
116 Correct 90 ms 5640 KB Output is correct