답안 #970446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970446 2024-04-26T14:25:53 Z maxFedorchuk Joker (BOI20_joker) C++17
100 / 100
357 ms 16752 KB
#include <bits/stdc++.h>
#define va first
#define vb second
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int,int> pii;
	
const int MN = 2e5+5;
	
int N,M,Q,pos;
int par[MN<<1],sz[MN<<1],ans[MN];
pii E[MN];
	
vector<pii> qu;
vector<int> cnt;
	
int fnd(int u)
{
	return u==par[u] ? u : fnd(par[u]);
}
	
void join(int u, int v)
{
	u = fnd(u), v = fnd(v);
	if(u==v) u = v = 0;
	if(sz[u]>sz[v]) swap(u,v);
	qu.push_back({u,v});
	par[u] = v;
	sz[v] += sz[u];
	
}
	
void upt(int x)
{
	if(x>M){
		join(0,0);
		join(0,0);
		cnt.push_back(0);
		return;
	}
	if(!x){
		for(int i=0; i<2; i++){
			pii q = qu.back();
			sz[q.vb] -= sz[q.va];
			par[q.va] = q.va;
			qu.pop_back();
		}
		pos -= cnt.back();
		cnt.pop_back();
	}
	else{
		join(E[x].va,E[x].vb+N);
		join(E[x].va+N,E[x].vb);
		if(fnd(E[x].va)==fnd(E[x].va+N)){
			pos++;
			cnt.push_back(1);
		}
		else cnt.push_back(0);
	}
}
	
void solve(int s, int e, int x, int y)
{
	if(s>e) return;
	int m = (s+e)/2;
	int z = y;
	for(int i=s; i<m; i++) upt(i);
	while(1){
		upt(z);
		if(pos||z==m){
			ans[m] = z;
			break;
		}
		z--;
	}
	for(int i=z; i<=y; i++) upt(0);
	for(int i=s; i<m; i++) upt(0);
	
	for(int i=z+1; i<=y; i++) upt(i);	
	solve(s,m-1,x,z);
	for(int i=z+1; i<=y; i++) upt(0);	
	
	for(int i=s; i<=m; i++) upt(i);
	solve(m+1,e,max(m+1,z),y);
	for(int i=s; i<=m; i++) upt(0);
}
	
int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> N >> M >> Q;
	
	for(int i=1; i<=M; i++) cin >> E[i].va >> E[i].vb;
	
	for(int i=1; i<=2*N; i++){
		par[i] = i;
		sz[i] = 1;
	}
	solve(1,M,1,M+1);
	
	while(Q--){
		int l,r;
		cin >> l >> r;
		cout << (r<ans[l] ? "YES\n" : "NO\n");
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4560 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 2 ms 4488 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4560 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 2 ms 4488 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 2 ms 4440 KB Output is correct
30 Correct 3 ms 4440 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 3 ms 4444 KB Output is correct
33 Correct 3 ms 4444 KB Output is correct
34 Correct 2 ms 4524 KB Output is correct
35 Correct 3 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 3 ms 4684 KB Output is correct
38 Correct 3 ms 4440 KB Output is correct
39 Correct 2 ms 4656 KB Output is correct
40 Correct 2 ms 4440 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4440 KB Output is correct
44 Correct 3 ms 4656 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 3 ms 4444 KB Output is correct
47 Correct 3 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 3 ms 4444 KB Output is correct
50 Correct 2 ms 4444 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4440 KB Output is correct
53 Correct 3 ms 4444 KB Output is correct
54 Correct 3 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 225 ms 15616 KB Output is correct
4 Correct 310 ms 15352 KB Output is correct
5 Correct 183 ms 15444 KB Output is correct
6 Correct 252 ms 14648 KB Output is correct
7 Correct 268 ms 15384 KB Output is correct
8 Correct 280 ms 13840 KB Output is correct
9 Correct 304 ms 14012 KB Output is correct
10 Correct 333 ms 15216 KB Output is correct
11 Correct 254 ms 14776 KB Output is correct
12 Correct 269 ms 15372 KB Output is correct
13 Correct 266 ms 14108 KB Output is correct
14 Correct 285 ms 15180 KB Output is correct
15 Correct 343 ms 15480 KB Output is correct
16 Correct 354 ms 15416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4560 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 2 ms 4488 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 225 ms 15616 KB Output is correct
30 Correct 310 ms 15352 KB Output is correct
31 Correct 183 ms 15444 KB Output is correct
32 Correct 252 ms 14648 KB Output is correct
33 Correct 268 ms 15384 KB Output is correct
34 Correct 280 ms 13840 KB Output is correct
35 Correct 304 ms 14012 KB Output is correct
36 Correct 333 ms 15216 KB Output is correct
37 Correct 254 ms 14776 KB Output is correct
38 Correct 269 ms 15372 KB Output is correct
39 Correct 266 ms 14108 KB Output is correct
40 Correct 285 ms 15180 KB Output is correct
41 Correct 343 ms 15480 KB Output is correct
42 Correct 354 ms 15416 KB Output is correct
43 Correct 266 ms 15596 KB Output is correct
44 Correct 325 ms 15380 KB Output is correct
45 Correct 261 ms 15868 KB Output is correct
46 Correct 256 ms 15100 KB Output is correct
47 Correct 254 ms 15608 KB Output is correct
48 Correct 315 ms 15096 KB Output is correct
49 Correct 345 ms 15888 KB Output is correct
50 Correct 234 ms 15168 KB Output is correct
51 Correct 270 ms 16384 KB Output is correct
52 Correct 330 ms 16376 KB Output is correct
53 Correct 270 ms 14564 KB Output is correct
54 Correct 340 ms 15480 KB Output is correct
55 Correct 357 ms 15496 KB Output is correct
56 Correct 332 ms 15864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4560 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 2 ms 4488 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 2 ms 4440 KB Output is correct
30 Correct 3 ms 4440 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 3 ms 4444 KB Output is correct
33 Correct 3 ms 4444 KB Output is correct
34 Correct 2 ms 4524 KB Output is correct
35 Correct 3 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 3 ms 4684 KB Output is correct
38 Correct 3 ms 4440 KB Output is correct
39 Correct 2 ms 4656 KB Output is correct
40 Correct 2 ms 4440 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4440 KB Output is correct
44 Correct 3 ms 4656 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 3 ms 4444 KB Output is correct
47 Correct 3 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 3 ms 4444 KB Output is correct
50 Correct 2 ms 4444 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4440 KB Output is correct
53 Correct 3 ms 4444 KB Output is correct
54 Correct 3 ms 4440 KB Output is correct
55 Correct 208 ms 13544 KB Output is correct
56 Correct 277 ms 13576 KB Output is correct
57 Correct 164 ms 13724 KB Output is correct
58 Correct 226 ms 12780 KB Output is correct
59 Correct 293 ms 13988 KB Output is correct
60 Correct 350 ms 13824 KB Output is correct
61 Correct 243 ms 13984 KB Output is correct
62 Correct 268 ms 14084 KB Output is correct
63 Correct 247 ms 13568 KB Output is correct
64 Correct 328 ms 13100 KB Output is correct
65 Correct 316 ms 15104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4560 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 2 ms 4488 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 2 ms 4440 KB Output is correct
30 Correct 3 ms 4440 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 3 ms 4444 KB Output is correct
33 Correct 3 ms 4444 KB Output is correct
34 Correct 2 ms 4524 KB Output is correct
35 Correct 3 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 3 ms 4684 KB Output is correct
38 Correct 3 ms 4440 KB Output is correct
39 Correct 2 ms 4656 KB Output is correct
40 Correct 2 ms 4440 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4440 KB Output is correct
44 Correct 3 ms 4656 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 3 ms 4444 KB Output is correct
47 Correct 3 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 3 ms 4444 KB Output is correct
50 Correct 2 ms 4444 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4440 KB Output is correct
53 Correct 3 ms 4444 KB Output is correct
54 Correct 3 ms 4440 KB Output is correct
55 Correct 225 ms 15616 KB Output is correct
56 Correct 310 ms 15352 KB Output is correct
57 Correct 183 ms 15444 KB Output is correct
58 Correct 252 ms 14648 KB Output is correct
59 Correct 268 ms 15384 KB Output is correct
60 Correct 280 ms 13840 KB Output is correct
61 Correct 304 ms 14012 KB Output is correct
62 Correct 333 ms 15216 KB Output is correct
63 Correct 254 ms 14776 KB Output is correct
64 Correct 269 ms 15372 KB Output is correct
65 Correct 266 ms 14108 KB Output is correct
66 Correct 285 ms 15180 KB Output is correct
67 Correct 343 ms 15480 KB Output is correct
68 Correct 354 ms 15416 KB Output is correct
69 Correct 266 ms 15596 KB Output is correct
70 Correct 325 ms 15380 KB Output is correct
71 Correct 261 ms 15868 KB Output is correct
72 Correct 256 ms 15100 KB Output is correct
73 Correct 254 ms 15608 KB Output is correct
74 Correct 315 ms 15096 KB Output is correct
75 Correct 345 ms 15888 KB Output is correct
76 Correct 234 ms 15168 KB Output is correct
77 Correct 270 ms 16384 KB Output is correct
78 Correct 330 ms 16376 KB Output is correct
79 Correct 270 ms 14564 KB Output is correct
80 Correct 340 ms 15480 KB Output is correct
81 Correct 357 ms 15496 KB Output is correct
82 Correct 332 ms 15864 KB Output is correct
83 Correct 208 ms 13544 KB Output is correct
84 Correct 277 ms 13576 KB Output is correct
85 Correct 164 ms 13724 KB Output is correct
86 Correct 226 ms 12780 KB Output is correct
87 Correct 293 ms 13988 KB Output is correct
88 Correct 350 ms 13824 KB Output is correct
89 Correct 243 ms 13984 KB Output is correct
90 Correct 268 ms 14084 KB Output is correct
91 Correct 247 ms 13568 KB Output is correct
92 Correct 328 ms 13100 KB Output is correct
93 Correct 316 ms 15104 KB Output is correct
94 Correct 230 ms 16124 KB Output is correct
95 Correct 271 ms 16380 KB Output is correct
96 Correct 189 ms 16380 KB Output is correct
97 Correct 271 ms 15612 KB Output is correct
98 Correct 267 ms 15864 KB Output is correct
99 Correct 308 ms 15352 KB Output is correct
100 Correct 334 ms 16520 KB Output is correct
101 Correct 243 ms 15612 KB Output is correct
102 Correct 281 ms 16188 KB Output is correct
103 Correct 312 ms 16636 KB Output is correct
104 Correct 279 ms 15844 KB Output is correct
105 Correct 357 ms 16408 KB Output is correct
106 Correct 355 ms 16720 KB Output is correct
107 Correct 178 ms 16752 KB Output is correct
108 Correct 227 ms 15308 KB Output is correct
109 Correct 221 ms 16104 KB Output is correct
110 Correct 214 ms 16284 KB Output is correct
111 Correct 221 ms 15888 KB Output is correct
112 Correct 226 ms 15304 KB Output is correct
113 Correct 237 ms 15508 KB Output is correct
114 Correct 228 ms 15348 KB Output is correct
115 Correct 231 ms 15732 KB Output is correct
116 Correct 240 ms 15964 KB Output is correct