답안 #877273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877273 2023-11-23T05:17:22 Z anhduc2701 Joker (BOI20_joker) C++17
49 / 100
2000 ms 22476 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second 
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int n,m,q;
pair<int,int>ed[maxn];
vector<int>G[maxn];
int col[maxn];
int ok=0;
int par[maxn];
int lt[maxn];
int rt[maxn];
vector<int>que[maxn];
inline int fin(int u){
	if(par[u]==u)return u;
	int k=fin(par[u]);
	col[u]=col[par[u]]^col[u];
	return par[u]=k;
}
inline void join(int a,int b){
	int u=fin(a);
	int v=fin(b);
	if(u==v){
		if(col[a]==col[b]){
			ok=1;
		}
		return;
	}
	if(u>v){
		swap(u,v);
		swap(a,b);
	}
	col[v]=col[a]^col[b]^1;
	par[v]=u;
}
bool ans[maxn];
signed main(){
	// freopen("input.inp","r",stdin);
	// freopen("output.out","w",stdout);
	cin.tie(0),cout.tie(0)->sync_with_stdio(0);
	cin >> n >> m >> q;
	for(int i=1;i<=m;i++){
		cin >> ed[i].fi >> ed[i].se;
	}
	if(q<=2000){
		for(int i=1;i<=q;i++){
			cin >> lt[i] >> rt[i];
			for(int j=1;j<=n;j++){
				col[j]=0;
				par[j]=j;
			}
			ok=0;
			for(int j=1;j<=lt[i]-1;j++){
				join(ed[j].fi,ed[j].se);
			}
			for(int j=rt[i]+1;j<=m;j++){
				join(ed[j].fi,ed[j].se);
			}
			if(ok==1){
				cout << "YES\n";
			}
			else{
				cout << "NO\n";
			}
		}
	}
	else{
		for(int i=1;i<=q;i++){
			cin >> lt[i] >> rt[i];
		}
		for(int i=1;i<=min(m,200);i++){
			for(int j=1;j<=m;j++)que[j].clear();
			for(int j=1;j<=q;j++){
				if(lt[j]==i ){
					que[rt[j]].pb(j);
				}
			}
			for(int j=1;j<=n;j++){
				par[j]=j;
				col[j]=0;
			}
			ok=0;
			for(int j=1;j<i;j++){
				join(ed[j].fi,ed[j].se);
			}
			for(int j=m;j>=i;j--){
				for(auto v:que[j]){
					ans[v]=ok;
				}
				join(ed[j].fi,ed[j].se);
			}
		}
		for(int i=1;i<=q;i++){
			if(ans[i])cout << "YES\n";
			else cout << "NO\n";
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 4 ms 12888 KB Output is correct
3 Correct 4 ms 13036 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 4 ms 12888 KB Output is correct
10 Correct 5 ms 13060 KB Output is correct
11 Correct 4 ms 12892 KB Output is correct
12 Correct 4 ms 12972 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 4 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 4 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 5 ms 12892 KB Output is correct
20 Correct 3 ms 12900 KB Output is correct
21 Correct 3 ms 12896 KB Output is correct
22 Correct 4 ms 13152 KB Output is correct
23 Correct 4 ms 12900 KB Output is correct
24 Correct 3 ms 12896 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 13144 KB Output is correct
27 Correct 3 ms 12896 KB Output is correct
28 Correct 4 ms 12888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 4 ms 12888 KB Output is correct
3 Correct 4 ms 13036 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 4 ms 12888 KB Output is correct
10 Correct 5 ms 13060 KB Output is correct
11 Correct 4 ms 12892 KB Output is correct
12 Correct 4 ms 12972 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 4 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 4 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 5 ms 12892 KB Output is correct
20 Correct 3 ms 12900 KB Output is correct
21 Correct 3 ms 12896 KB Output is correct
22 Correct 4 ms 13152 KB Output is correct
23 Correct 4 ms 12900 KB Output is correct
24 Correct 3 ms 12896 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 13144 KB Output is correct
27 Correct 3 ms 12896 KB Output is correct
28 Correct 4 ms 12888 KB Output is correct
29 Correct 12 ms 12892 KB Output is correct
30 Correct 21 ms 12892 KB Output is correct
31 Correct 26 ms 12888 KB Output is correct
32 Correct 22 ms 13068 KB Output is correct
33 Correct 17 ms 12892 KB Output is correct
34 Correct 22 ms 12900 KB Output is correct
35 Correct 27 ms 12900 KB Output is correct
36 Correct 14 ms 12896 KB Output is correct
37 Correct 16 ms 13080 KB Output is correct
38 Correct 17 ms 12892 KB Output is correct
39 Correct 14 ms 12892 KB Output is correct
40 Correct 18 ms 13068 KB Output is correct
41 Correct 17 ms 12892 KB Output is correct
42 Correct 21 ms 12892 KB Output is correct
43 Correct 20 ms 12892 KB Output is correct
44 Correct 27 ms 12896 KB Output is correct
45 Correct 29 ms 12888 KB Output is correct
46 Correct 27 ms 12896 KB Output is correct
47 Correct 19 ms 12892 KB Output is correct
48 Correct 27 ms 12892 KB Output is correct
49 Correct 21 ms 12888 KB Output is correct
50 Correct 21 ms 12892 KB Output is correct
51 Correct 18 ms 12888 KB Output is correct
52 Correct 19 ms 12888 KB Output is correct
53 Correct 22 ms 12892 KB Output is correct
54 Correct 23 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 4 ms 12888 KB Output is correct
3 Correct 517 ms 22476 KB Output is correct
4 Correct 727 ms 21088 KB Output is correct
5 Correct 865 ms 21700 KB Output is correct
6 Correct 843 ms 21500 KB Output is correct
7 Correct 854 ms 21700 KB Output is correct
8 Correct 615 ms 21044 KB Output is correct
9 Correct 817 ms 21076 KB Output is correct
10 Correct 995 ms 21328 KB Output is correct
11 Correct 867 ms 21424 KB Output is correct
12 Correct 894 ms 21608 KB Output is correct
13 Correct 360 ms 21328 KB Output is correct
14 Correct 649 ms 21468 KB Output is correct
15 Correct 921 ms 21476 KB Output is correct
16 Correct 1059 ms 21588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 4 ms 12888 KB Output is correct
3 Correct 4 ms 13036 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 4 ms 12888 KB Output is correct
10 Correct 5 ms 13060 KB Output is correct
11 Correct 4 ms 12892 KB Output is correct
12 Correct 4 ms 12972 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 4 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 4 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 5 ms 12892 KB Output is correct
20 Correct 3 ms 12900 KB Output is correct
21 Correct 3 ms 12896 KB Output is correct
22 Correct 4 ms 13152 KB Output is correct
23 Correct 4 ms 12900 KB Output is correct
24 Correct 3 ms 12896 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 13144 KB Output is correct
27 Correct 3 ms 12896 KB Output is correct
28 Correct 4 ms 12888 KB Output is correct
29 Correct 517 ms 22476 KB Output is correct
30 Correct 727 ms 21088 KB Output is correct
31 Correct 865 ms 21700 KB Output is correct
32 Correct 843 ms 21500 KB Output is correct
33 Correct 854 ms 21700 KB Output is correct
34 Correct 615 ms 21044 KB Output is correct
35 Correct 817 ms 21076 KB Output is correct
36 Correct 995 ms 21328 KB Output is correct
37 Correct 867 ms 21424 KB Output is correct
38 Correct 894 ms 21608 KB Output is correct
39 Correct 360 ms 21328 KB Output is correct
40 Correct 649 ms 21468 KB Output is correct
41 Correct 921 ms 21476 KB Output is correct
42 Correct 1059 ms 21588 KB Output is correct
43 Correct 499 ms 22464 KB Output is correct
44 Correct 734 ms 21700 KB Output is correct
45 Correct 744 ms 21196 KB Output is correct
46 Correct 863 ms 21252 KB Output is correct
47 Correct 896 ms 21120 KB Output is correct
48 Correct 837 ms 21728 KB Output is correct
49 Correct 1000 ms 21952 KB Output is correct
50 Correct 853 ms 21236 KB Output is correct
51 Correct 913 ms 21284 KB Output is correct
52 Correct 919 ms 21192 KB Output is correct
53 Correct 368 ms 21152 KB Output is correct
54 Correct 797 ms 21412 KB Output is correct
55 Correct 998 ms 21240 KB Output is correct
56 Correct 1010 ms 21200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 4 ms 12888 KB Output is correct
3 Correct 4 ms 13036 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 4 ms 12888 KB Output is correct
10 Correct 5 ms 13060 KB Output is correct
11 Correct 4 ms 12892 KB Output is correct
12 Correct 4 ms 12972 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 4 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 4 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 5 ms 12892 KB Output is correct
20 Correct 3 ms 12900 KB Output is correct
21 Correct 3 ms 12896 KB Output is correct
22 Correct 4 ms 13152 KB Output is correct
23 Correct 4 ms 12900 KB Output is correct
24 Correct 3 ms 12896 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 13144 KB Output is correct
27 Correct 3 ms 12896 KB Output is correct
28 Correct 4 ms 12888 KB Output is correct
29 Correct 12 ms 12892 KB Output is correct
30 Correct 21 ms 12892 KB Output is correct
31 Correct 26 ms 12888 KB Output is correct
32 Correct 22 ms 13068 KB Output is correct
33 Correct 17 ms 12892 KB Output is correct
34 Correct 22 ms 12900 KB Output is correct
35 Correct 27 ms 12900 KB Output is correct
36 Correct 14 ms 12896 KB Output is correct
37 Correct 16 ms 13080 KB Output is correct
38 Correct 17 ms 12892 KB Output is correct
39 Correct 14 ms 12892 KB Output is correct
40 Correct 18 ms 13068 KB Output is correct
41 Correct 17 ms 12892 KB Output is correct
42 Correct 21 ms 12892 KB Output is correct
43 Correct 20 ms 12892 KB Output is correct
44 Correct 27 ms 12896 KB Output is correct
45 Correct 29 ms 12888 KB Output is correct
46 Correct 27 ms 12896 KB Output is correct
47 Correct 19 ms 12892 KB Output is correct
48 Correct 27 ms 12892 KB Output is correct
49 Correct 21 ms 12888 KB Output is correct
50 Correct 21 ms 12892 KB Output is correct
51 Correct 18 ms 12888 KB Output is correct
52 Correct 19 ms 12888 KB Output is correct
53 Correct 22 ms 12892 KB Output is correct
54 Correct 23 ms 12892 KB Output is correct
55 Execution timed out 2053 ms 16880 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12888 KB Output is correct
2 Correct 4 ms 12888 KB Output is correct
3 Correct 4 ms 13036 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 4 ms 12892 KB Output is correct
9 Correct 4 ms 12888 KB Output is correct
10 Correct 5 ms 13060 KB Output is correct
11 Correct 4 ms 12892 KB Output is correct
12 Correct 4 ms 12972 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 4 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 4 ms 12892 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 5 ms 12892 KB Output is correct
20 Correct 3 ms 12900 KB Output is correct
21 Correct 3 ms 12896 KB Output is correct
22 Correct 4 ms 13152 KB Output is correct
23 Correct 4 ms 12900 KB Output is correct
24 Correct 3 ms 12896 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 13144 KB Output is correct
27 Correct 3 ms 12896 KB Output is correct
28 Correct 4 ms 12888 KB Output is correct
29 Correct 12 ms 12892 KB Output is correct
30 Correct 21 ms 12892 KB Output is correct
31 Correct 26 ms 12888 KB Output is correct
32 Correct 22 ms 13068 KB Output is correct
33 Correct 17 ms 12892 KB Output is correct
34 Correct 22 ms 12900 KB Output is correct
35 Correct 27 ms 12900 KB Output is correct
36 Correct 14 ms 12896 KB Output is correct
37 Correct 16 ms 13080 KB Output is correct
38 Correct 17 ms 12892 KB Output is correct
39 Correct 14 ms 12892 KB Output is correct
40 Correct 18 ms 13068 KB Output is correct
41 Correct 17 ms 12892 KB Output is correct
42 Correct 21 ms 12892 KB Output is correct
43 Correct 20 ms 12892 KB Output is correct
44 Correct 27 ms 12896 KB Output is correct
45 Correct 29 ms 12888 KB Output is correct
46 Correct 27 ms 12896 KB Output is correct
47 Correct 19 ms 12892 KB Output is correct
48 Correct 27 ms 12892 KB Output is correct
49 Correct 21 ms 12888 KB Output is correct
50 Correct 21 ms 12892 KB Output is correct
51 Correct 18 ms 12888 KB Output is correct
52 Correct 19 ms 12888 KB Output is correct
53 Correct 22 ms 12892 KB Output is correct
54 Correct 23 ms 12892 KB Output is correct
55 Correct 517 ms 22476 KB Output is correct
56 Correct 727 ms 21088 KB Output is correct
57 Correct 865 ms 21700 KB Output is correct
58 Correct 843 ms 21500 KB Output is correct
59 Correct 854 ms 21700 KB Output is correct
60 Correct 615 ms 21044 KB Output is correct
61 Correct 817 ms 21076 KB Output is correct
62 Correct 995 ms 21328 KB Output is correct
63 Correct 867 ms 21424 KB Output is correct
64 Correct 894 ms 21608 KB Output is correct
65 Correct 360 ms 21328 KB Output is correct
66 Correct 649 ms 21468 KB Output is correct
67 Correct 921 ms 21476 KB Output is correct
68 Correct 1059 ms 21588 KB Output is correct
69 Correct 499 ms 22464 KB Output is correct
70 Correct 734 ms 21700 KB Output is correct
71 Correct 744 ms 21196 KB Output is correct
72 Correct 863 ms 21252 KB Output is correct
73 Correct 896 ms 21120 KB Output is correct
74 Correct 837 ms 21728 KB Output is correct
75 Correct 1000 ms 21952 KB Output is correct
76 Correct 853 ms 21236 KB Output is correct
77 Correct 913 ms 21284 KB Output is correct
78 Correct 919 ms 21192 KB Output is correct
79 Correct 368 ms 21152 KB Output is correct
80 Correct 797 ms 21412 KB Output is correct
81 Correct 998 ms 21240 KB Output is correct
82 Correct 1010 ms 21200 KB Output is correct
83 Execution timed out 2053 ms 16880 KB Time limit exceeded
84 Halted 0 ms 0 KB -