답안 #573411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573411 2022-06-06T14:47:02 Z amunduzbaev Joker (BOI20_joker) C++17
100 / 100
609 ms 34416 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long

const int N = 2e5 + 5;
vector<int> edges[N];
int sz[N], par[N], c[N], is[N], R[N];
ar<int, 2> e[N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, m, q; cin>>n>>m>>q;
	for(int i=1;i<=m;i++){
		cin>>e[i][0]>>e[i][1];
		edges[e[i][0]].push_back(e[i][1]);
		edges[e[i][1]].push_back(e[i][0]);
	}
	
	for(int i=0;i<N;i++) sz[i] = 1, par[i] = i;
	function<ar<int, 2>(int)> f = [&](int x) -> ar<int, 2>{
		if(par[x ] == x) return {x, c[x]};
		auto t = f(par[x]);
		return {t[0], t[1] ^ c[x]};
	};
	int cnt = 0;
	vector<ar<int, 3>> last;
	auto merge = [&](int a, int b){
		//~ cout<<a<<" "<<b<<"\n";
		auto ax = f(a), bx = f(b);
		a = ax[0], b = bx[0];
		//~ cout<<a<<" "<<b<<"\n";
		if(a == b){
			cnt += (ax[1] == bx[1]);
			return;
		}
		if(sz[a] < sz[b]) swap(a, b);
		int is = 0;
		if(ax[1] == bx[1]) is = 1;
		par[b] = a, sz[a] += sz[b];
		c[b] ^= is;
		last.push_back({a, b, is});
	};
	
	auto roll_back = [&](int m){
		while((int)last.size() > m){
			auto x = last.back(); last.pop_back();
			par[x[1]] = x[1], sz[x[0]] -= sz[x[1]];
			c[x[1]] ^= x[2];
		}
	};
	
	auto add = [&](int x){
		merge(e[x][0], e[x][1]);
	};
	
	function<void(int, int, int, int)> dnc = [&](int l, int r, int lx, int rx){
		//~ cout<<l<<" "<<r<<endl;
		if(l > r) return;
		assert(lx <= rx);
		int m = (l + r) >> 1;
		int sz = last.size(), cc = cnt;
		for(int x=l;x<m;x++) add(x);
		int x = rx;
		while(!cnt && x >= m){
			add(x);
			x--;
		}
		R[m] = x;
		//~ cout<<m<<" "<<x<<"\n";
		
		roll_back(sz), cnt = cc;
		for(int x=rx;x>R[m];x--) add(x);
		dnc(l, m - 1, lx, R[m]);
		roll_back(sz), cnt = cc;
		for(int x=l;x<=m;x++) add(x);
		dnc(m + 1, r, R[m], rx);
		roll_back(sz), cnt = cc;
	};
	
	dnc(1, m, 1, m);
	//~ for(int i=1;i<=n;i++) cout<<R[i]<<" ";
	//~ cout<<"\n";
	
	while(q--){
		int l, r; cin>>l>>r;
		if(r <= R[l]) cout<<"YES\n";
		else cout<<"NO\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8104 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 6 ms 8100 KB Output is correct
4 Correct 4 ms 8100 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 6 ms 8148 KB Output is correct
8 Correct 5 ms 8148 KB Output is correct
9 Correct 5 ms 8096 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 6 ms 8148 KB Output is correct
12 Correct 6 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 4 ms 8100 KB Output is correct
15 Correct 5 ms 8148 KB Output is correct
16 Correct 5 ms 8148 KB Output is correct
17 Correct 5 ms 8100 KB Output is correct
18 Correct 5 ms 8148 KB Output is correct
19 Correct 4 ms 8100 KB Output is correct
20 Correct 6 ms 8108 KB Output is correct
21 Correct 5 ms 8104 KB Output is correct
22 Correct 5 ms 8104 KB Output is correct
23 Correct 6 ms 8104 KB Output is correct
24 Correct 4 ms 8148 KB Output is correct
25 Correct 6 ms 8148 KB Output is correct
26 Correct 4 ms 8148 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 4 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8104 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 6 ms 8100 KB Output is correct
4 Correct 4 ms 8100 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 6 ms 8148 KB Output is correct
8 Correct 5 ms 8148 KB Output is correct
9 Correct 5 ms 8096 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 6 ms 8148 KB Output is correct
12 Correct 6 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 4 ms 8100 KB Output is correct
15 Correct 5 ms 8148 KB Output is correct
16 Correct 5 ms 8148 KB Output is correct
17 Correct 5 ms 8100 KB Output is correct
18 Correct 5 ms 8148 KB Output is correct
19 Correct 4 ms 8100 KB Output is correct
20 Correct 6 ms 8108 KB Output is correct
21 Correct 5 ms 8104 KB Output is correct
22 Correct 5 ms 8104 KB Output is correct
23 Correct 6 ms 8104 KB Output is correct
24 Correct 4 ms 8148 KB Output is correct
25 Correct 6 ms 8148 KB Output is correct
26 Correct 4 ms 8148 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 4 ms 8148 KB Output is correct
29 Correct 5 ms 8236 KB Output is correct
30 Correct 6 ms 8408 KB Output is correct
31 Correct 6 ms 8404 KB Output is correct
32 Correct 6 ms 8368 KB Output is correct
33 Correct 7 ms 8368 KB Output is correct
34 Correct 8 ms 8404 KB Output is correct
35 Correct 7 ms 8440 KB Output is correct
36 Correct 6 ms 8276 KB Output is correct
37 Correct 9 ms 8368 KB Output is correct
38 Correct 7 ms 8368 KB Output is correct
39 Correct 6 ms 8372 KB Output is correct
40 Correct 6 ms 8368 KB Output is correct
41 Correct 6 ms 8404 KB Output is correct
42 Correct 6 ms 8276 KB Output is correct
43 Correct 7 ms 8372 KB Output is correct
44 Correct 6 ms 8276 KB Output is correct
45 Correct 7 ms 8412 KB Output is correct
46 Correct 7 ms 8404 KB Output is correct
47 Correct 6 ms 8276 KB Output is correct
48 Correct 7 ms 8276 KB Output is correct
49 Correct 7 ms 8372 KB Output is correct
50 Correct 7 ms 8404 KB Output is correct
51 Correct 7 ms 8276 KB Output is correct
52 Correct 8 ms 8372 KB Output is correct
53 Correct 7 ms 8372 KB Output is correct
54 Correct 7 ms 8368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8104 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 224 ms 25488 KB Output is correct
4 Correct 458 ms 30552 KB Output is correct
5 Correct 253 ms 30672 KB Output is correct
6 Correct 330 ms 27100 KB Output is correct
7 Correct 327 ms 27124 KB Output is correct
8 Correct 355 ms 24720 KB Output is correct
9 Correct 366 ms 26348 KB Output is correct
10 Correct 521 ms 29748 KB Output is correct
11 Correct 346 ms 26716 KB Output is correct
12 Correct 329 ms 29760 KB Output is correct
13 Correct 323 ms 23532 KB Output is correct
14 Correct 333 ms 25264 KB Output is correct
15 Correct 441 ms 29424 KB Output is correct
16 Correct 497 ms 30304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8104 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 6 ms 8100 KB Output is correct
4 Correct 4 ms 8100 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 6 ms 8148 KB Output is correct
8 Correct 5 ms 8148 KB Output is correct
9 Correct 5 ms 8096 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 6 ms 8148 KB Output is correct
12 Correct 6 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 4 ms 8100 KB Output is correct
15 Correct 5 ms 8148 KB Output is correct
16 Correct 5 ms 8148 KB Output is correct
17 Correct 5 ms 8100 KB Output is correct
18 Correct 5 ms 8148 KB Output is correct
19 Correct 4 ms 8100 KB Output is correct
20 Correct 6 ms 8108 KB Output is correct
21 Correct 5 ms 8104 KB Output is correct
22 Correct 5 ms 8104 KB Output is correct
23 Correct 6 ms 8104 KB Output is correct
24 Correct 4 ms 8148 KB Output is correct
25 Correct 6 ms 8148 KB Output is correct
26 Correct 4 ms 8148 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 4 ms 8148 KB Output is correct
29 Correct 224 ms 25488 KB Output is correct
30 Correct 458 ms 30552 KB Output is correct
31 Correct 253 ms 30672 KB Output is correct
32 Correct 330 ms 27100 KB Output is correct
33 Correct 327 ms 27124 KB Output is correct
34 Correct 355 ms 24720 KB Output is correct
35 Correct 366 ms 26348 KB Output is correct
36 Correct 521 ms 29748 KB Output is correct
37 Correct 346 ms 26716 KB Output is correct
38 Correct 329 ms 29760 KB Output is correct
39 Correct 323 ms 23532 KB Output is correct
40 Correct 333 ms 25264 KB Output is correct
41 Correct 441 ms 29424 KB Output is correct
42 Correct 497 ms 30304 KB Output is correct
43 Correct 231 ms 25860 KB Output is correct
44 Correct 468 ms 31148 KB Output is correct
45 Correct 371 ms 31380 KB Output is correct
46 Correct 355 ms 27348 KB Output is correct
47 Correct 363 ms 27336 KB Output is correct
48 Correct 475 ms 26948 KB Output is correct
49 Correct 513 ms 30316 KB Output is correct
50 Correct 342 ms 26364 KB Output is correct
51 Correct 394 ms 29368 KB Output is correct
52 Correct 490 ms 30376 KB Output is correct
53 Correct 432 ms 23840 KB Output is correct
54 Correct 483 ms 26356 KB Output is correct
55 Correct 537 ms 29504 KB Output is correct
56 Correct 609 ms 30420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8104 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 6 ms 8100 KB Output is correct
4 Correct 4 ms 8100 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 6 ms 8148 KB Output is correct
8 Correct 5 ms 8148 KB Output is correct
9 Correct 5 ms 8096 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 6 ms 8148 KB Output is correct
12 Correct 6 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 4 ms 8100 KB Output is correct
15 Correct 5 ms 8148 KB Output is correct
16 Correct 5 ms 8148 KB Output is correct
17 Correct 5 ms 8100 KB Output is correct
18 Correct 5 ms 8148 KB Output is correct
19 Correct 4 ms 8100 KB Output is correct
20 Correct 6 ms 8108 KB Output is correct
21 Correct 5 ms 8104 KB Output is correct
22 Correct 5 ms 8104 KB Output is correct
23 Correct 6 ms 8104 KB Output is correct
24 Correct 4 ms 8148 KB Output is correct
25 Correct 6 ms 8148 KB Output is correct
26 Correct 4 ms 8148 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 4 ms 8148 KB Output is correct
29 Correct 5 ms 8236 KB Output is correct
30 Correct 6 ms 8408 KB Output is correct
31 Correct 6 ms 8404 KB Output is correct
32 Correct 6 ms 8368 KB Output is correct
33 Correct 7 ms 8368 KB Output is correct
34 Correct 8 ms 8404 KB Output is correct
35 Correct 7 ms 8440 KB Output is correct
36 Correct 6 ms 8276 KB Output is correct
37 Correct 9 ms 8368 KB Output is correct
38 Correct 7 ms 8368 KB Output is correct
39 Correct 6 ms 8372 KB Output is correct
40 Correct 6 ms 8368 KB Output is correct
41 Correct 6 ms 8404 KB Output is correct
42 Correct 6 ms 8276 KB Output is correct
43 Correct 7 ms 8372 KB Output is correct
44 Correct 6 ms 8276 KB Output is correct
45 Correct 7 ms 8412 KB Output is correct
46 Correct 7 ms 8404 KB Output is correct
47 Correct 6 ms 8276 KB Output is correct
48 Correct 7 ms 8276 KB Output is correct
49 Correct 7 ms 8372 KB Output is correct
50 Correct 7 ms 8404 KB Output is correct
51 Correct 7 ms 8276 KB Output is correct
52 Correct 8 ms 8372 KB Output is correct
53 Correct 7 ms 8372 KB Output is correct
54 Correct 7 ms 8368 KB Output is correct
55 Correct 252 ms 23144 KB Output is correct
56 Correct 442 ms 28792 KB Output is correct
57 Correct 260 ms 29484 KB Output is correct
58 Correct 323 ms 24804 KB Output is correct
59 Correct 418 ms 24564 KB Output is correct
60 Correct 499 ms 29204 KB Output is correct
61 Correct 319 ms 24520 KB Output is correct
62 Correct 383 ms 29132 KB Output is correct
63 Correct 326 ms 22064 KB Output is correct
64 Correct 395 ms 25372 KB Output is correct
65 Correct 503 ms 29152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8104 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 6 ms 8100 KB Output is correct
4 Correct 4 ms 8100 KB Output is correct
5 Correct 4 ms 8148 KB Output is correct
6 Correct 5 ms 8148 KB Output is correct
7 Correct 6 ms 8148 KB Output is correct
8 Correct 5 ms 8148 KB Output is correct
9 Correct 5 ms 8096 KB Output is correct
10 Correct 5 ms 8148 KB Output is correct
11 Correct 6 ms 8148 KB Output is correct
12 Correct 6 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 4 ms 8100 KB Output is correct
15 Correct 5 ms 8148 KB Output is correct
16 Correct 5 ms 8148 KB Output is correct
17 Correct 5 ms 8100 KB Output is correct
18 Correct 5 ms 8148 KB Output is correct
19 Correct 4 ms 8100 KB Output is correct
20 Correct 6 ms 8108 KB Output is correct
21 Correct 5 ms 8104 KB Output is correct
22 Correct 5 ms 8104 KB Output is correct
23 Correct 6 ms 8104 KB Output is correct
24 Correct 4 ms 8148 KB Output is correct
25 Correct 6 ms 8148 KB Output is correct
26 Correct 4 ms 8148 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 4 ms 8148 KB Output is correct
29 Correct 5 ms 8236 KB Output is correct
30 Correct 6 ms 8408 KB Output is correct
31 Correct 6 ms 8404 KB Output is correct
32 Correct 6 ms 8368 KB Output is correct
33 Correct 7 ms 8368 KB Output is correct
34 Correct 8 ms 8404 KB Output is correct
35 Correct 7 ms 8440 KB Output is correct
36 Correct 6 ms 8276 KB Output is correct
37 Correct 9 ms 8368 KB Output is correct
38 Correct 7 ms 8368 KB Output is correct
39 Correct 6 ms 8372 KB Output is correct
40 Correct 6 ms 8368 KB Output is correct
41 Correct 6 ms 8404 KB Output is correct
42 Correct 6 ms 8276 KB Output is correct
43 Correct 7 ms 8372 KB Output is correct
44 Correct 6 ms 8276 KB Output is correct
45 Correct 7 ms 8412 KB Output is correct
46 Correct 7 ms 8404 KB Output is correct
47 Correct 6 ms 8276 KB Output is correct
48 Correct 7 ms 8276 KB Output is correct
49 Correct 7 ms 8372 KB Output is correct
50 Correct 7 ms 8404 KB Output is correct
51 Correct 7 ms 8276 KB Output is correct
52 Correct 8 ms 8372 KB Output is correct
53 Correct 7 ms 8372 KB Output is correct
54 Correct 7 ms 8368 KB Output is correct
55 Correct 224 ms 25488 KB Output is correct
56 Correct 458 ms 30552 KB Output is correct
57 Correct 253 ms 30672 KB Output is correct
58 Correct 330 ms 27100 KB Output is correct
59 Correct 327 ms 27124 KB Output is correct
60 Correct 355 ms 24720 KB Output is correct
61 Correct 366 ms 26348 KB Output is correct
62 Correct 521 ms 29748 KB Output is correct
63 Correct 346 ms 26716 KB Output is correct
64 Correct 329 ms 29760 KB Output is correct
65 Correct 323 ms 23532 KB Output is correct
66 Correct 333 ms 25264 KB Output is correct
67 Correct 441 ms 29424 KB Output is correct
68 Correct 497 ms 30304 KB Output is correct
69 Correct 231 ms 25860 KB Output is correct
70 Correct 468 ms 31148 KB Output is correct
71 Correct 371 ms 31380 KB Output is correct
72 Correct 355 ms 27348 KB Output is correct
73 Correct 363 ms 27336 KB Output is correct
74 Correct 475 ms 26948 KB Output is correct
75 Correct 513 ms 30316 KB Output is correct
76 Correct 342 ms 26364 KB Output is correct
77 Correct 394 ms 29368 KB Output is correct
78 Correct 490 ms 30376 KB Output is correct
79 Correct 432 ms 23840 KB Output is correct
80 Correct 483 ms 26356 KB Output is correct
81 Correct 537 ms 29504 KB Output is correct
82 Correct 609 ms 30420 KB Output is correct
83 Correct 252 ms 23144 KB Output is correct
84 Correct 442 ms 28792 KB Output is correct
85 Correct 260 ms 29484 KB Output is correct
86 Correct 323 ms 24804 KB Output is correct
87 Correct 418 ms 24564 KB Output is correct
88 Correct 499 ms 29204 KB Output is correct
89 Correct 319 ms 24520 KB Output is correct
90 Correct 383 ms 29132 KB Output is correct
91 Correct 326 ms 22064 KB Output is correct
92 Correct 395 ms 25372 KB Output is correct
93 Correct 503 ms 29152 KB Output is correct
94 Correct 305 ms 26460 KB Output is correct
95 Correct 379 ms 32072 KB Output is correct
96 Correct 285 ms 31528 KB Output is correct
97 Correct 428 ms 28096 KB Output is correct
98 Correct 392 ms 28124 KB Output is correct
99 Correct 448 ms 26180 KB Output is correct
100 Correct 472 ms 31364 KB Output is correct
101 Correct 323 ms 27096 KB Output is correct
102 Correct 362 ms 29508 KB Output is correct
103 Correct 392 ms 31324 KB Output is correct
104 Correct 387 ms 25376 KB Output is correct
105 Correct 431 ms 28700 KB Output is correct
106 Correct 550 ms 30836 KB Output is correct
107 Correct 193 ms 34416 KB Output is correct
108 Correct 297 ms 26260 KB Output is correct
109 Correct 258 ms 26188 KB Output is correct
110 Correct 273 ms 26300 KB Output is correct
111 Correct 294 ms 26200 KB Output is correct
112 Correct 305 ms 26216 KB Output is correct
113 Correct 301 ms 26168 KB Output is correct
114 Correct 276 ms 26252 KB Output is correct
115 Correct 263 ms 26208 KB Output is correct
116 Correct 265 ms 26212 KB Output is correct