Submission #573412

# Submission time Handle Problem Language Result Execution time Memory
573412 2022-06-06T14:47:18 Z amunduzbaev Joker (BOI20_joker) C++17
100 / 100
554 ms 20764 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";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 5 ms 6556 KB Output is correct
3 Correct 5 ms 6484 KB Output is correct
4 Correct 4 ms 6484 KB Output is correct
5 Correct 6 ms 6484 KB Output is correct
6 Correct 4 ms 6556 KB Output is correct
7 Correct 6 ms 6612 KB Output is correct
8 Correct 4 ms 6560 KB Output is correct
9 Correct 4 ms 6612 KB Output is correct
10 Correct 4 ms 6624 KB Output is correct
11 Correct 4 ms 6612 KB Output is correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 5 ms 6520 KB Output is correct
14 Correct 4 ms 6560 KB Output is correct
15 Correct 4 ms 6612 KB Output is correct
16 Correct 5 ms 6560 KB Output is correct
17 Correct 4 ms 6560 KB Output is correct
18 Correct 4 ms 6612 KB Output is correct
19 Correct 5 ms 6612 KB Output is correct
20 Correct 4 ms 6612 KB Output is correct
21 Correct 4 ms 6612 KB Output is correct
22 Correct 3 ms 6612 KB Output is correct
23 Correct 4 ms 6612 KB Output is correct
24 Correct 4 ms 6612 KB Output is correct
25 Correct 4 ms 6612 KB Output is correct
26 Correct 4 ms 6612 KB Output is correct
27 Correct 5 ms 6568 KB Output is correct
28 Correct 4 ms 6612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 5 ms 6556 KB Output is correct
3 Correct 5 ms 6484 KB Output is correct
4 Correct 4 ms 6484 KB Output is correct
5 Correct 6 ms 6484 KB Output is correct
6 Correct 4 ms 6556 KB Output is correct
7 Correct 6 ms 6612 KB Output is correct
8 Correct 4 ms 6560 KB Output is correct
9 Correct 4 ms 6612 KB Output is correct
10 Correct 4 ms 6624 KB Output is correct
11 Correct 4 ms 6612 KB Output is correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 5 ms 6520 KB Output is correct
14 Correct 4 ms 6560 KB Output is correct
15 Correct 4 ms 6612 KB Output is correct
16 Correct 5 ms 6560 KB Output is correct
17 Correct 4 ms 6560 KB Output is correct
18 Correct 4 ms 6612 KB Output is correct
19 Correct 5 ms 6612 KB Output is correct
20 Correct 4 ms 6612 KB Output is correct
21 Correct 4 ms 6612 KB Output is correct
22 Correct 3 ms 6612 KB Output is correct
23 Correct 4 ms 6612 KB Output is correct
24 Correct 4 ms 6612 KB Output is correct
25 Correct 4 ms 6612 KB Output is correct
26 Correct 4 ms 6612 KB Output is correct
27 Correct 5 ms 6568 KB Output is correct
28 Correct 4 ms 6612 KB Output is correct
29 Correct 8 ms 6612 KB Output is correct
30 Correct 6 ms 6772 KB Output is correct
31 Correct 8 ms 6740 KB Output is correct
32 Correct 7 ms 6732 KB Output is correct
33 Correct 6 ms 6612 KB Output is correct
34 Correct 6 ms 6696 KB Output is correct
35 Correct 7 ms 6756 KB Output is correct
36 Correct 6 ms 6588 KB Output is correct
37 Correct 7 ms 6664 KB Output is correct
38 Correct 7 ms 6780 KB Output is correct
39 Correct 6 ms 6656 KB Output is correct
40 Correct 8 ms 6652 KB Output is correct
41 Correct 6 ms 6740 KB Output is correct
42 Correct 6 ms 6636 KB Output is correct
43 Correct 6 ms 6696 KB Output is correct
44 Correct 6 ms 6700 KB Output is correct
45 Correct 6 ms 6700 KB Output is correct
46 Correct 8 ms 6772 KB Output is correct
47 Correct 6 ms 6740 KB Output is correct
48 Correct 5 ms 6740 KB Output is correct
49 Correct 6 ms 6736 KB Output is correct
50 Correct 7 ms 6740 KB Output is correct
51 Correct 6 ms 6740 KB Output is correct
52 Correct 8 ms 6612 KB Output is correct
53 Correct 7 ms 6700 KB Output is correct
54 Correct 7 ms 6740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 5 ms 6556 KB Output is correct
3 Correct 279 ms 15372 KB Output is correct
4 Correct 467 ms 20032 KB Output is correct
5 Correct 279 ms 19424 KB Output is correct
6 Correct 372 ms 16532 KB Output is correct
7 Correct 358 ms 16536 KB Output is correct
8 Correct 384 ms 15308 KB Output is correct
9 Correct 430 ms 16632 KB Output is correct
10 Correct 468 ms 19176 KB Output is correct
11 Correct 371 ms 16384 KB Output is correct
12 Correct 379 ms 18832 KB Output is correct
13 Correct 344 ms 14164 KB Output is correct
14 Correct 371 ms 15224 KB Output is correct
15 Correct 546 ms 18332 KB Output is correct
16 Correct 499 ms 19152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 5 ms 6556 KB Output is correct
3 Correct 5 ms 6484 KB Output is correct
4 Correct 4 ms 6484 KB Output is correct
5 Correct 6 ms 6484 KB Output is correct
6 Correct 4 ms 6556 KB Output is correct
7 Correct 6 ms 6612 KB Output is correct
8 Correct 4 ms 6560 KB Output is correct
9 Correct 4 ms 6612 KB Output is correct
10 Correct 4 ms 6624 KB Output is correct
11 Correct 4 ms 6612 KB Output is correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 5 ms 6520 KB Output is correct
14 Correct 4 ms 6560 KB Output is correct
15 Correct 4 ms 6612 KB Output is correct
16 Correct 5 ms 6560 KB Output is correct
17 Correct 4 ms 6560 KB Output is correct
18 Correct 4 ms 6612 KB Output is correct
19 Correct 5 ms 6612 KB Output is correct
20 Correct 4 ms 6612 KB Output is correct
21 Correct 4 ms 6612 KB Output is correct
22 Correct 3 ms 6612 KB Output is correct
23 Correct 4 ms 6612 KB Output is correct
24 Correct 4 ms 6612 KB Output is correct
25 Correct 4 ms 6612 KB Output is correct
26 Correct 4 ms 6612 KB Output is correct
27 Correct 5 ms 6568 KB Output is correct
28 Correct 4 ms 6612 KB Output is correct
29 Correct 279 ms 15372 KB Output is correct
30 Correct 467 ms 20032 KB Output is correct
31 Correct 279 ms 19424 KB Output is correct
32 Correct 372 ms 16532 KB Output is correct
33 Correct 358 ms 16536 KB Output is correct
34 Correct 384 ms 15308 KB Output is correct
35 Correct 430 ms 16632 KB Output is correct
36 Correct 468 ms 19176 KB Output is correct
37 Correct 371 ms 16384 KB Output is correct
38 Correct 379 ms 18832 KB Output is correct
39 Correct 344 ms 14164 KB Output is correct
40 Correct 371 ms 15224 KB Output is correct
41 Correct 546 ms 18332 KB Output is correct
42 Correct 499 ms 19152 KB Output is correct
43 Correct 293 ms 15344 KB Output is correct
44 Correct 489 ms 20192 KB Output is correct
45 Correct 360 ms 19892 KB Output is correct
46 Correct 304 ms 16364 KB Output is correct
47 Correct 327 ms 15724 KB Output is correct
48 Correct 371 ms 15572 KB Output is correct
49 Correct 516 ms 18148 KB Output is correct
50 Correct 318 ms 14800 KB Output is correct
51 Correct 386 ms 17224 KB Output is correct
52 Correct 421 ms 18172 KB Output is correct
53 Correct 325 ms 12908 KB Output is correct
54 Correct 405 ms 14772 KB Output is correct
55 Correct 490 ms 17228 KB Output is correct
56 Correct 492 ms 18076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 5 ms 6556 KB Output is correct
3 Correct 5 ms 6484 KB Output is correct
4 Correct 4 ms 6484 KB Output is correct
5 Correct 6 ms 6484 KB Output is correct
6 Correct 4 ms 6556 KB Output is correct
7 Correct 6 ms 6612 KB Output is correct
8 Correct 4 ms 6560 KB Output is correct
9 Correct 4 ms 6612 KB Output is correct
10 Correct 4 ms 6624 KB Output is correct
11 Correct 4 ms 6612 KB Output is correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 5 ms 6520 KB Output is correct
14 Correct 4 ms 6560 KB Output is correct
15 Correct 4 ms 6612 KB Output is correct
16 Correct 5 ms 6560 KB Output is correct
17 Correct 4 ms 6560 KB Output is correct
18 Correct 4 ms 6612 KB Output is correct
19 Correct 5 ms 6612 KB Output is correct
20 Correct 4 ms 6612 KB Output is correct
21 Correct 4 ms 6612 KB Output is correct
22 Correct 3 ms 6612 KB Output is correct
23 Correct 4 ms 6612 KB Output is correct
24 Correct 4 ms 6612 KB Output is correct
25 Correct 4 ms 6612 KB Output is correct
26 Correct 4 ms 6612 KB Output is correct
27 Correct 5 ms 6568 KB Output is correct
28 Correct 4 ms 6612 KB Output is correct
29 Correct 8 ms 6612 KB Output is correct
30 Correct 6 ms 6772 KB Output is correct
31 Correct 8 ms 6740 KB Output is correct
32 Correct 7 ms 6732 KB Output is correct
33 Correct 6 ms 6612 KB Output is correct
34 Correct 6 ms 6696 KB Output is correct
35 Correct 7 ms 6756 KB Output is correct
36 Correct 6 ms 6588 KB Output is correct
37 Correct 7 ms 6664 KB Output is correct
38 Correct 7 ms 6780 KB Output is correct
39 Correct 6 ms 6656 KB Output is correct
40 Correct 8 ms 6652 KB Output is correct
41 Correct 6 ms 6740 KB Output is correct
42 Correct 6 ms 6636 KB Output is correct
43 Correct 6 ms 6696 KB Output is correct
44 Correct 6 ms 6700 KB Output is correct
45 Correct 6 ms 6700 KB Output is correct
46 Correct 8 ms 6772 KB Output is correct
47 Correct 6 ms 6740 KB Output is correct
48 Correct 5 ms 6740 KB Output is correct
49 Correct 6 ms 6736 KB Output is correct
50 Correct 7 ms 6740 KB Output is correct
51 Correct 6 ms 6740 KB Output is correct
52 Correct 8 ms 6612 KB Output is correct
53 Correct 7 ms 6700 KB Output is correct
54 Correct 7 ms 6740 KB Output is correct
55 Correct 264 ms 14080 KB Output is correct
56 Correct 385 ms 18964 KB Output is correct
57 Correct 229 ms 18568 KB Output is correct
58 Correct 290 ms 15204 KB Output is correct
59 Correct 336 ms 15128 KB Output is correct
60 Correct 554 ms 17804 KB Output is correct
61 Correct 323 ms 15128 KB Output is correct
62 Correct 317 ms 18208 KB Output is correct
63 Correct 279 ms 13368 KB Output is correct
64 Correct 371 ms 15644 KB Output is correct
65 Correct 404 ms 17948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 5 ms 6556 KB Output is correct
3 Correct 5 ms 6484 KB Output is correct
4 Correct 4 ms 6484 KB Output is correct
5 Correct 6 ms 6484 KB Output is correct
6 Correct 4 ms 6556 KB Output is correct
7 Correct 6 ms 6612 KB Output is correct
8 Correct 4 ms 6560 KB Output is correct
9 Correct 4 ms 6612 KB Output is correct
10 Correct 4 ms 6624 KB Output is correct
11 Correct 4 ms 6612 KB Output is correct
12 Correct 4 ms 6612 KB Output is correct
13 Correct 5 ms 6520 KB Output is correct
14 Correct 4 ms 6560 KB Output is correct
15 Correct 4 ms 6612 KB Output is correct
16 Correct 5 ms 6560 KB Output is correct
17 Correct 4 ms 6560 KB Output is correct
18 Correct 4 ms 6612 KB Output is correct
19 Correct 5 ms 6612 KB Output is correct
20 Correct 4 ms 6612 KB Output is correct
21 Correct 4 ms 6612 KB Output is correct
22 Correct 3 ms 6612 KB Output is correct
23 Correct 4 ms 6612 KB Output is correct
24 Correct 4 ms 6612 KB Output is correct
25 Correct 4 ms 6612 KB Output is correct
26 Correct 4 ms 6612 KB Output is correct
27 Correct 5 ms 6568 KB Output is correct
28 Correct 4 ms 6612 KB Output is correct
29 Correct 8 ms 6612 KB Output is correct
30 Correct 6 ms 6772 KB Output is correct
31 Correct 8 ms 6740 KB Output is correct
32 Correct 7 ms 6732 KB Output is correct
33 Correct 6 ms 6612 KB Output is correct
34 Correct 6 ms 6696 KB Output is correct
35 Correct 7 ms 6756 KB Output is correct
36 Correct 6 ms 6588 KB Output is correct
37 Correct 7 ms 6664 KB Output is correct
38 Correct 7 ms 6780 KB Output is correct
39 Correct 6 ms 6656 KB Output is correct
40 Correct 8 ms 6652 KB Output is correct
41 Correct 6 ms 6740 KB Output is correct
42 Correct 6 ms 6636 KB Output is correct
43 Correct 6 ms 6696 KB Output is correct
44 Correct 6 ms 6700 KB Output is correct
45 Correct 6 ms 6700 KB Output is correct
46 Correct 8 ms 6772 KB Output is correct
47 Correct 6 ms 6740 KB Output is correct
48 Correct 5 ms 6740 KB Output is correct
49 Correct 6 ms 6736 KB Output is correct
50 Correct 7 ms 6740 KB Output is correct
51 Correct 6 ms 6740 KB Output is correct
52 Correct 8 ms 6612 KB Output is correct
53 Correct 7 ms 6700 KB Output is correct
54 Correct 7 ms 6740 KB Output is correct
55 Correct 279 ms 15372 KB Output is correct
56 Correct 467 ms 20032 KB Output is correct
57 Correct 279 ms 19424 KB Output is correct
58 Correct 372 ms 16532 KB Output is correct
59 Correct 358 ms 16536 KB Output is correct
60 Correct 384 ms 15308 KB Output is correct
61 Correct 430 ms 16632 KB Output is correct
62 Correct 468 ms 19176 KB Output is correct
63 Correct 371 ms 16384 KB Output is correct
64 Correct 379 ms 18832 KB Output is correct
65 Correct 344 ms 14164 KB Output is correct
66 Correct 371 ms 15224 KB Output is correct
67 Correct 546 ms 18332 KB Output is correct
68 Correct 499 ms 19152 KB Output is correct
69 Correct 293 ms 15344 KB Output is correct
70 Correct 489 ms 20192 KB Output is correct
71 Correct 360 ms 19892 KB Output is correct
72 Correct 304 ms 16364 KB Output is correct
73 Correct 327 ms 15724 KB Output is correct
74 Correct 371 ms 15572 KB Output is correct
75 Correct 516 ms 18148 KB Output is correct
76 Correct 318 ms 14800 KB Output is correct
77 Correct 386 ms 17224 KB Output is correct
78 Correct 421 ms 18172 KB Output is correct
79 Correct 325 ms 12908 KB Output is correct
80 Correct 405 ms 14772 KB Output is correct
81 Correct 490 ms 17228 KB Output is correct
82 Correct 492 ms 18076 KB Output is correct
83 Correct 264 ms 14080 KB Output is correct
84 Correct 385 ms 18964 KB Output is correct
85 Correct 229 ms 18568 KB Output is correct
86 Correct 290 ms 15204 KB Output is correct
87 Correct 336 ms 15128 KB Output is correct
88 Correct 554 ms 17804 KB Output is correct
89 Correct 323 ms 15128 KB Output is correct
90 Correct 317 ms 18208 KB Output is correct
91 Correct 279 ms 13368 KB Output is correct
92 Correct 371 ms 15644 KB Output is correct
93 Correct 404 ms 17948 KB Output is correct
94 Correct 240 ms 14784 KB Output is correct
95 Correct 346 ms 19516 KB Output is correct
96 Correct 235 ms 18608 KB Output is correct
97 Correct 325 ms 15880 KB Output is correct
98 Correct 316 ms 15940 KB Output is correct
99 Correct 341 ms 14664 KB Output is correct
100 Correct 387 ms 18412 KB Output is correct
101 Correct 364 ms 15200 KB Output is correct
102 Correct 330 ms 17468 KB Output is correct
103 Correct 418 ms 18464 KB Output is correct
104 Correct 324 ms 13928 KB Output is correct
105 Correct 421 ms 16508 KB Output is correct
106 Correct 493 ms 17984 KB Output is correct
107 Correct 189 ms 20764 KB Output is correct
108 Correct 240 ms 14624 KB Output is correct
109 Correct 248 ms 14716 KB Output is correct
110 Correct 244 ms 14676 KB Output is correct
111 Correct 238 ms 14532 KB Output is correct
112 Correct 259 ms 14560 KB Output is correct
113 Correct 242 ms 14364 KB Output is correct
114 Correct 252 ms 14276 KB Output is correct
115 Correct 238 ms 14408 KB Output is correct
116 Correct 262 ms 14404 KB Output is correct