답안 #652667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
652667 2022-10-23T17:11:09 Z lovrot Joker (BOI20_joker) C++17
100 / 100
302 ms 15760 KB
#include <bits/stdc++.h> 

#define X first
#define Y second
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int N = 2 * 1e5 + 10;

int n, m, q;
int par[N], eq[N], siz[N], opt[N];
pii edge[N];

stack<pair<pii, pair<pii, pii>>> event;

pii Find(int a){
	if(par[a] == a) return {a, eq[a]};
	pii p = Find(par[a]);
	return {p.X, p.Y ^ eq[a]};
}

bool Union(int a, int b){
	pii resa = Find(a);
	pii resb = Find(b);
	a = resa.X;
	b = resb.X;
	int x = resa.Y;
	int y = resb.Y;
	
	event.push({{a, b}, {{eq[a], eq[b]}, {siz[a], siz[b]}}});
	
	if(a == b){
		return x ^ y;
	}
	
	if(siz[a] < siz[b]){
		swap(a, b);
		swap(x, y);
	}
		
	eq[b] = !(x ^ y);
	par[b] = a;
	siz[a] = siz[a] + siz[b];
	return true;
}

bool change(int x, bool state){
	if(state){
		return Union(edge[x].X, edge[x].Y);
	} else { 
		pair<pii, pair<pii, pii>> e = event.top();
		event.pop();
		int u = e.X.X;
		int v = e.X.Y;
		par[u] = u;
		par[v] = v;
		eq[u] = e.Y.X.X;
		eq[v] = e.Y.X.Y;
		siz[u] = e.Y.Y.X;
		siz[v] = e.Y.Y.Y;
	}
	return true;
}

void include(int l, int r, bool state){
	for(l; l <= r; l++){
		change(l, state);
	}
}

void divcon(int l, int r, int L, int R){
	if(l > r) return;
	int mi = (l + r) / 2;
	int k = R;
	
	include(L, mi - 1, true);
	while(change(k, true)){
		k--;
	}
	opt[mi] = k;
	include(k, R, false);
	divcon(mi + 1, r, mi, R);
	include(L, mi - 1, false);
	
	include(k + 1, R, true);
	divcon(l, mi - 1, L, k);
	include(k + 1, R, false);
}

int main(){
	for(int i = 1; i < N; i++){
		par[i] = i;
		eq[i] = 0;
		siz[i] = 1;
	}
	
	scanf("%d%d%d", &n, &m, &q);
	
	for(int i = 1; i <= m; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		edge[i] = {a, b};
	}
	
	int lastc = 0;
	int ind = 0;
	for(int i = 1; i <= m; i++){
		lastc = i;
		if(!change(i, true)){ 
			ind = i;
			break;
		}
	}	
		
	//printf("breaking ind = %d\n", ind);
		
	include(1, lastc, 0);	
	
	if(ind){
		divcon(1, ind, 1, m);
		for(int i = ind + 1; i <= m; i++) opt[i] = m + 1;
	} else {
		for(int i = 1; i <= m; i++){
			opt[i] = -1;
		}
	} 
	
	//printf("opt %d = %d\n", 4, opt[4]);
	
	for(int i = 0; i < q; i++){
		int l, r;
		scanf("%d%d", &l, &r);
		if(r < opt[l]) printf("YES\n");
		else printf("NO\n"); 
	} 
	return 0;
}

Compilation message

Joker.cpp: In function 'void include(int, int, bool)':
Joker.cpp:70:6: warning: statement has no effect [-Wunused-value]
   70 |  for(l; l <= r; l++){
      |      ^
Joker.cpp: In function 'int main()':
Joker.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |  scanf("%d%d%d", &n, &m, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |   scanf("%d%d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~
Joker.cpp:136:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |   scanf("%d%d", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2656 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2656 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2656 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2656 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2656 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2656 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 3 ms 2720 KB Output is correct
30 Correct 3 ms 2668 KB Output is correct
31 Correct 3 ms 2664 KB Output is correct
32 Correct 3 ms 2644 KB Output is correct
33 Correct 3 ms 2644 KB Output is correct
34 Correct 3 ms 2688 KB Output is correct
35 Correct 4 ms 2664 KB Output is correct
36 Correct 3 ms 2644 KB Output is correct
37 Correct 4 ms 2772 KB Output is correct
38 Correct 3 ms 2772 KB Output is correct
39 Correct 3 ms 2696 KB Output is correct
40 Correct 3 ms 2672 KB Output is correct
41 Correct 3 ms 2644 KB Output is correct
42 Correct 3 ms 2644 KB Output is correct
43 Correct 3 ms 2664 KB Output is correct
44 Correct 3 ms 2644 KB Output is correct
45 Correct 3 ms 2664 KB Output is correct
46 Correct 4 ms 2664 KB Output is correct
47 Correct 3 ms 2644 KB Output is correct
48 Correct 3 ms 2644 KB Output is correct
49 Correct 3 ms 2700 KB Output is correct
50 Correct 3 ms 2704 KB Output is correct
51 Correct 4 ms 2664 KB Output is correct
52 Correct 3 ms 2696 KB Output is correct
53 Correct 3 ms 2644 KB Output is correct
54 Correct 3 ms 2700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 192 ms 7856 KB Output is correct
4 Correct 89 ms 13932 KB Output is correct
5 Correct 173 ms 11516 KB Output is correct
6 Correct 141 ms 12056 KB Output is correct
7 Correct 147 ms 12112 KB Output is correct
8 Correct 174 ms 11384 KB Output is correct
9 Correct 192 ms 11452 KB Output is correct
10 Correct 262 ms 11204 KB Output is correct
11 Correct 201 ms 12048 KB Output is correct
12 Correct 217 ms 11580 KB Output is correct
13 Correct 181 ms 11796 KB Output is correct
14 Correct 172 ms 11996 KB Output is correct
15 Correct 252 ms 12240 KB Output is correct
16 Correct 264 ms 11620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2656 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2656 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2656 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 192 ms 7856 KB Output is correct
30 Correct 89 ms 13932 KB Output is correct
31 Correct 173 ms 11516 KB Output is correct
32 Correct 141 ms 12056 KB Output is correct
33 Correct 147 ms 12112 KB Output is correct
34 Correct 174 ms 11384 KB Output is correct
35 Correct 192 ms 11452 KB Output is correct
36 Correct 262 ms 11204 KB Output is correct
37 Correct 201 ms 12048 KB Output is correct
38 Correct 217 ms 11580 KB Output is correct
39 Correct 181 ms 11796 KB Output is correct
40 Correct 172 ms 11996 KB Output is correct
41 Correct 252 ms 12240 KB Output is correct
42 Correct 264 ms 11620 KB Output is correct
43 Correct 184 ms 12312 KB Output is correct
44 Correct 98 ms 14460 KB Output is correct
45 Correct 276 ms 14880 KB Output is correct
46 Correct 137 ms 12364 KB Output is correct
47 Correct 152 ms 12324 KB Output is correct
48 Correct 208 ms 12140 KB Output is correct
49 Correct 271 ms 12308 KB Output is correct
50 Correct 193 ms 12224 KB Output is correct
51 Correct 190 ms 12544 KB Output is correct
52 Correct 216 ms 12376 KB Output is correct
53 Correct 176 ms 12100 KB Output is correct
54 Correct 201 ms 12236 KB Output is correct
55 Correct 228 ms 12396 KB Output is correct
56 Correct 266 ms 12588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2656 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2656 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2656 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 3 ms 2720 KB Output is correct
30 Correct 3 ms 2668 KB Output is correct
31 Correct 3 ms 2664 KB Output is correct
32 Correct 3 ms 2644 KB Output is correct
33 Correct 3 ms 2644 KB Output is correct
34 Correct 3 ms 2688 KB Output is correct
35 Correct 4 ms 2664 KB Output is correct
36 Correct 3 ms 2644 KB Output is correct
37 Correct 4 ms 2772 KB Output is correct
38 Correct 3 ms 2772 KB Output is correct
39 Correct 3 ms 2696 KB Output is correct
40 Correct 3 ms 2672 KB Output is correct
41 Correct 3 ms 2644 KB Output is correct
42 Correct 3 ms 2644 KB Output is correct
43 Correct 3 ms 2664 KB Output is correct
44 Correct 3 ms 2644 KB Output is correct
45 Correct 3 ms 2664 KB Output is correct
46 Correct 4 ms 2664 KB Output is correct
47 Correct 3 ms 2644 KB Output is correct
48 Correct 3 ms 2644 KB Output is correct
49 Correct 3 ms 2700 KB Output is correct
50 Correct 3 ms 2704 KB Output is correct
51 Correct 4 ms 2664 KB Output is correct
52 Correct 3 ms 2696 KB Output is correct
53 Correct 3 ms 2644 KB Output is correct
54 Correct 3 ms 2700 KB Output is correct
55 Correct 141 ms 9664 KB Output is correct
56 Correct 56 ms 12344 KB Output is correct
57 Correct 142 ms 11484 KB Output is correct
58 Correct 104 ms 9732 KB Output is correct
59 Correct 160 ms 9652 KB Output is correct
60 Correct 239 ms 9824 KB Output is correct
61 Correct 183 ms 9744 KB Output is correct
62 Correct 225 ms 9692 KB Output is correct
63 Correct 131 ms 9664 KB Output is correct
64 Correct 181 ms 9780 KB Output is correct
65 Correct 238 ms 9872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2656 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2656 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2656 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 3 ms 2720 KB Output is correct
30 Correct 3 ms 2668 KB Output is correct
31 Correct 3 ms 2664 KB Output is correct
32 Correct 3 ms 2644 KB Output is correct
33 Correct 3 ms 2644 KB Output is correct
34 Correct 3 ms 2688 KB Output is correct
35 Correct 4 ms 2664 KB Output is correct
36 Correct 3 ms 2644 KB Output is correct
37 Correct 4 ms 2772 KB Output is correct
38 Correct 3 ms 2772 KB Output is correct
39 Correct 3 ms 2696 KB Output is correct
40 Correct 3 ms 2672 KB Output is correct
41 Correct 3 ms 2644 KB Output is correct
42 Correct 3 ms 2644 KB Output is correct
43 Correct 3 ms 2664 KB Output is correct
44 Correct 3 ms 2644 KB Output is correct
45 Correct 3 ms 2664 KB Output is correct
46 Correct 4 ms 2664 KB Output is correct
47 Correct 3 ms 2644 KB Output is correct
48 Correct 3 ms 2644 KB Output is correct
49 Correct 3 ms 2700 KB Output is correct
50 Correct 3 ms 2704 KB Output is correct
51 Correct 4 ms 2664 KB Output is correct
52 Correct 3 ms 2696 KB Output is correct
53 Correct 3 ms 2644 KB Output is correct
54 Correct 3 ms 2700 KB Output is correct
55 Correct 192 ms 7856 KB Output is correct
56 Correct 89 ms 13932 KB Output is correct
57 Correct 173 ms 11516 KB Output is correct
58 Correct 141 ms 12056 KB Output is correct
59 Correct 147 ms 12112 KB Output is correct
60 Correct 174 ms 11384 KB Output is correct
61 Correct 192 ms 11452 KB Output is correct
62 Correct 262 ms 11204 KB Output is correct
63 Correct 201 ms 12048 KB Output is correct
64 Correct 217 ms 11580 KB Output is correct
65 Correct 181 ms 11796 KB Output is correct
66 Correct 172 ms 11996 KB Output is correct
67 Correct 252 ms 12240 KB Output is correct
68 Correct 264 ms 11620 KB Output is correct
69 Correct 184 ms 12312 KB Output is correct
70 Correct 98 ms 14460 KB Output is correct
71 Correct 276 ms 14880 KB Output is correct
72 Correct 137 ms 12364 KB Output is correct
73 Correct 152 ms 12324 KB Output is correct
74 Correct 208 ms 12140 KB Output is correct
75 Correct 271 ms 12308 KB Output is correct
76 Correct 193 ms 12224 KB Output is correct
77 Correct 190 ms 12544 KB Output is correct
78 Correct 216 ms 12376 KB Output is correct
79 Correct 176 ms 12100 KB Output is correct
80 Correct 201 ms 12236 KB Output is correct
81 Correct 228 ms 12396 KB Output is correct
82 Correct 266 ms 12588 KB Output is correct
83 Correct 141 ms 9664 KB Output is correct
84 Correct 56 ms 12344 KB Output is correct
85 Correct 142 ms 11484 KB Output is correct
86 Correct 104 ms 9732 KB Output is correct
87 Correct 160 ms 9652 KB Output is correct
88 Correct 239 ms 9824 KB Output is correct
89 Correct 183 ms 9744 KB Output is correct
90 Correct 225 ms 9692 KB Output is correct
91 Correct 131 ms 9664 KB Output is correct
92 Correct 181 ms 9780 KB Output is correct
93 Correct 238 ms 9872 KB Output is correct
94 Correct 194 ms 12944 KB Output is correct
95 Correct 302 ms 14276 KB Output is correct
96 Correct 178 ms 11596 KB Output is correct
97 Correct 172 ms 13004 KB Output is correct
98 Correct 164 ms 12632 KB Output is correct
99 Correct 188 ms 13020 KB Output is correct
100 Correct 218 ms 13248 KB Output is correct
101 Correct 196 ms 13212 KB Output is correct
102 Correct 254 ms 13200 KB Output is correct
103 Correct 237 ms 13344 KB Output is correct
104 Correct 187 ms 12900 KB Output is correct
105 Correct 229 ms 13092 KB Output is correct
106 Correct 267 ms 13208 KB Output is correct
107 Correct 150 ms 15760 KB Output is correct
108 Correct 190 ms 12808 KB Output is correct
109 Correct 191 ms 12796 KB Output is correct
110 Correct 181 ms 12856 KB Output is correct
111 Correct 179 ms 12804 KB Output is correct
112 Correct 188 ms 12732 KB Output is correct
113 Correct 184 ms 12860 KB Output is correct
114 Correct 180 ms 12724 KB Output is correct
115 Correct 190 ms 12720 KB Output is correct
116 Correct 184 ms 12724 KB Output is correct