Submission #936011

# Submission time Handle Problem Language Result Execution time Memory
936011 2024-02-29T23:57:34 Z MinaRagy06 Joker (BOI20_joker) C++17
100 / 100
355 ms 51380 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define md ((l + r) >> 1)

const int N = 200'005;
int par[N], sz[N], dep[N];
int gud;
array<int, 2> find(int u) {
	if (par[u] == u) {
		return {u, 0};
	}
	array<int, 2> v = find(par[u]);
	v[1] ^= dep[u];
	return v;
}
vector<pair<int*, int>> logs;
void assign(int *x, int y) {
	logs.push_back({x, *x});
	*x = y;
}
void rollback() {
	while (logs.back().first) {
		pair<int*, int> v = logs.back();
		logs.pop_back();
		*v.first = v.second;
	}
	logs.pop_back();
}
void join(int u, int v) {
	array<int, 2> pu = find(u), pv = find(v);
	if (pu[0] == pv[0]) {
		assign(&gud, gud && (dep[pv[0]] == (pv[1] ^ pu[1] ^ 1)));
		return;
	}
	if (sz[pu[0]] < sz[pv[0]]) {
		swap(u, v);
		swap(pu, pv);
	}
	assign(&par[pv[0]], pu[0]);
	assign(&dep[pv[0]], (pv[1] ^ pu[1] ^ 1));
	assign(&sz[pu[0]], sz[pu[0]] + sz[pv[0]]);
}
array<int, 2> a[N];
vector<int> seg[1 << 19];
void add(int i, int l, int r, int s, int e, int x) {
	if (s <= l && r <= e) {
		seg[i].push_back(x);
		return;
	}
	if (r < s || e < l) {
		return;
	}
	add(i << 1, l, md, s, e, x);
	add(i << 1 | 1, md + 1, r, s, e, x);
}
int ptr, mn;
int suf[N];
void solve(int i, int l, int r) {
	logs.push_back({NULL, 0});
	for (auto j : seg[i]) {
		join(a[j][0], a[j][1]);
	}
	if (l == r) {
		while (gud && l < ptr - 1) {
			assign(&ptr, ptr - 1);
			join(a[ptr][0], a[ptr][1]);
			mn = min(mn, ptr);
		}
		if (!gud) suf[l] = ptr;
	} else {
		solve(i << 1 | 1, md + 1, r);
		solve(i << 1, l, md);
	}
	rollback();
	while (ptr > mn) {
		assign(&ptr, ptr - 1);
		join(a[ptr][0], a[ptr][1]);
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= m; i++) {
		cin >> a[i][0] >> a[i][1];
	}
	for (int i = 1; i <= m; i++) {
		add(1, 0, m, i, m, i);
	}
	for (int i = 0; i <= m; i++) {
		suf[i] = 0;
	}
	for (int i = 1; i <= n; i++) {
		par[i] = i;
		sz[i] = 1;
		dep[i] = 0;
	}
	gud = 1;
	ptr = mn = m + 1;
	solve(1, 0, m);
// 	for (int i = 0; i <= m; i++) {
// 		cout << suf[i] << ' ';
// 	}
// 	cout << '\n';
	while (q--) {
		int l, r;
		cin >> l >> r;
		if (r < suf[l - 1]) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16732 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
3 Correct 3 ms 16728 KB Output is correct
4 Correct 3 ms 16728 KB Output is correct
5 Correct 3 ms 16732 KB Output is correct
6 Correct 3 ms 16732 KB Output is correct
7 Correct 3 ms 16900 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 4 ms 16816 KB Output is correct
10 Correct 3 ms 16732 KB Output is correct
11 Correct 3 ms 16732 KB Output is correct
12 Correct 4 ms 16732 KB Output is correct
13 Correct 4 ms 16728 KB Output is correct
14 Correct 3 ms 16732 KB Output is correct
15 Correct 3 ms 16732 KB Output is correct
16 Correct 3 ms 16732 KB Output is correct
17 Correct 3 ms 16728 KB Output is correct
18 Correct 3 ms 16732 KB Output is correct
19 Correct 4 ms 16732 KB Output is correct
20 Correct 3 ms 16732 KB Output is correct
21 Correct 3 ms 16732 KB Output is correct
22 Correct 4 ms 16732 KB Output is correct
23 Correct 3 ms 16732 KB Output is correct
24 Correct 4 ms 16732 KB Output is correct
25 Correct 4 ms 16732 KB Output is correct
26 Correct 3 ms 16728 KB Output is correct
27 Correct 3 ms 16732 KB Output is correct
28 Correct 3 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16732 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
3 Correct 3 ms 16728 KB Output is correct
4 Correct 3 ms 16728 KB Output is correct
5 Correct 3 ms 16732 KB Output is correct
6 Correct 3 ms 16732 KB Output is correct
7 Correct 3 ms 16900 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 4 ms 16816 KB Output is correct
10 Correct 3 ms 16732 KB Output is correct
11 Correct 3 ms 16732 KB Output is correct
12 Correct 4 ms 16732 KB Output is correct
13 Correct 4 ms 16728 KB Output is correct
14 Correct 3 ms 16732 KB Output is correct
15 Correct 3 ms 16732 KB Output is correct
16 Correct 3 ms 16732 KB Output is correct
17 Correct 3 ms 16728 KB Output is correct
18 Correct 3 ms 16732 KB Output is correct
19 Correct 4 ms 16732 KB Output is correct
20 Correct 3 ms 16732 KB Output is correct
21 Correct 3 ms 16732 KB Output is correct
22 Correct 4 ms 16732 KB Output is correct
23 Correct 3 ms 16732 KB Output is correct
24 Correct 4 ms 16732 KB Output is correct
25 Correct 4 ms 16732 KB Output is correct
26 Correct 3 ms 16728 KB Output is correct
27 Correct 3 ms 16732 KB Output is correct
28 Correct 3 ms 16732 KB Output is correct
29 Correct 5 ms 16988 KB Output is correct
30 Correct 7 ms 17480 KB Output is correct
31 Correct 5 ms 16984 KB Output is correct
32 Correct 5 ms 16988 KB Output is correct
33 Correct 5 ms 16988 KB Output is correct
34 Correct 5 ms 16988 KB Output is correct
35 Correct 7 ms 16988 KB Output is correct
36 Correct 6 ms 17240 KB Output is correct
37 Correct 6 ms 17244 KB Output is correct
38 Correct 6 ms 17244 KB Output is correct
39 Correct 5 ms 16988 KB Output is correct
40 Correct 5 ms 16988 KB Output is correct
41 Correct 5 ms 17016 KB Output is correct
42 Correct 6 ms 16988 KB Output is correct
43 Correct 5 ms 16984 KB Output is correct
44 Correct 5 ms 17112 KB Output is correct
45 Correct 5 ms 16988 KB Output is correct
46 Correct 7 ms 17136 KB Output is correct
47 Correct 5 ms 16988 KB Output is correct
48 Correct 5 ms 16988 KB Output is correct
49 Correct 6 ms 16988 KB Output is correct
50 Correct 6 ms 16988 KB Output is correct
51 Correct 5 ms 16988 KB Output is correct
52 Correct 6 ms 16988 KB Output is correct
53 Correct 5 ms 16988 KB Output is correct
54 Correct 6 ms 17208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16732 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
3 Correct 227 ms 39604 KB Output is correct
4 Correct 331 ms 50616 KB Output is correct
5 Correct 187 ms 49800 KB Output is correct
6 Correct 253 ms 41900 KB Output is correct
7 Correct 255 ms 41256 KB Output is correct
8 Correct 249 ms 40636 KB Output is correct
9 Correct 262 ms 40900 KB Output is correct
10 Correct 301 ms 50212 KB Output is correct
11 Correct 237 ms 41920 KB Output is correct
12 Correct 255 ms 43200 KB Output is correct
13 Correct 219 ms 38384 KB Output is correct
14 Correct 312 ms 42176 KB Output is correct
15 Correct 285 ms 42092 KB Output is correct
16 Correct 296 ms 50596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16732 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
3 Correct 3 ms 16728 KB Output is correct
4 Correct 3 ms 16728 KB Output is correct
5 Correct 3 ms 16732 KB Output is correct
6 Correct 3 ms 16732 KB Output is correct
7 Correct 3 ms 16900 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 4 ms 16816 KB Output is correct
10 Correct 3 ms 16732 KB Output is correct
11 Correct 3 ms 16732 KB Output is correct
12 Correct 4 ms 16732 KB Output is correct
13 Correct 4 ms 16728 KB Output is correct
14 Correct 3 ms 16732 KB Output is correct
15 Correct 3 ms 16732 KB Output is correct
16 Correct 3 ms 16732 KB Output is correct
17 Correct 3 ms 16728 KB Output is correct
18 Correct 3 ms 16732 KB Output is correct
19 Correct 4 ms 16732 KB Output is correct
20 Correct 3 ms 16732 KB Output is correct
21 Correct 3 ms 16732 KB Output is correct
22 Correct 4 ms 16732 KB Output is correct
23 Correct 3 ms 16732 KB Output is correct
24 Correct 4 ms 16732 KB Output is correct
25 Correct 4 ms 16732 KB Output is correct
26 Correct 3 ms 16728 KB Output is correct
27 Correct 3 ms 16732 KB Output is correct
28 Correct 3 ms 16732 KB Output is correct
29 Correct 227 ms 39604 KB Output is correct
30 Correct 331 ms 50616 KB Output is correct
31 Correct 187 ms 49800 KB Output is correct
32 Correct 253 ms 41900 KB Output is correct
33 Correct 255 ms 41256 KB Output is correct
34 Correct 249 ms 40636 KB Output is correct
35 Correct 262 ms 40900 KB Output is correct
36 Correct 301 ms 50212 KB Output is correct
37 Correct 237 ms 41920 KB Output is correct
38 Correct 255 ms 43200 KB Output is correct
39 Correct 219 ms 38384 KB Output is correct
40 Correct 312 ms 42176 KB Output is correct
41 Correct 285 ms 42092 KB Output is correct
42 Correct 296 ms 50596 KB Output is correct
43 Correct 226 ms 42988 KB Output is correct
44 Correct 330 ms 51380 KB Output is correct
45 Correct 355 ms 51160 KB Output is correct
46 Correct 251 ms 41652 KB Output is correct
47 Correct 257 ms 42884 KB Output is correct
48 Correct 268 ms 41656 KB Output is correct
49 Correct 294 ms 51128 KB Output is correct
50 Correct 238 ms 42076 KB Output is correct
51 Correct 248 ms 42804 KB Output is correct
52 Correct 259 ms 49592 KB Output is correct
53 Correct 227 ms 38464 KB Output is correct
54 Correct 288 ms 41748 KB Output is correct
55 Correct 317 ms 43416 KB Output is correct
56 Correct 292 ms 51132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16732 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
3 Correct 3 ms 16728 KB Output is correct
4 Correct 3 ms 16728 KB Output is correct
5 Correct 3 ms 16732 KB Output is correct
6 Correct 3 ms 16732 KB Output is correct
7 Correct 3 ms 16900 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 4 ms 16816 KB Output is correct
10 Correct 3 ms 16732 KB Output is correct
11 Correct 3 ms 16732 KB Output is correct
12 Correct 4 ms 16732 KB Output is correct
13 Correct 4 ms 16728 KB Output is correct
14 Correct 3 ms 16732 KB Output is correct
15 Correct 3 ms 16732 KB Output is correct
16 Correct 3 ms 16732 KB Output is correct
17 Correct 3 ms 16728 KB Output is correct
18 Correct 3 ms 16732 KB Output is correct
19 Correct 4 ms 16732 KB Output is correct
20 Correct 3 ms 16732 KB Output is correct
21 Correct 3 ms 16732 KB Output is correct
22 Correct 4 ms 16732 KB Output is correct
23 Correct 3 ms 16732 KB Output is correct
24 Correct 4 ms 16732 KB Output is correct
25 Correct 4 ms 16732 KB Output is correct
26 Correct 3 ms 16728 KB Output is correct
27 Correct 3 ms 16732 KB Output is correct
28 Correct 3 ms 16732 KB Output is correct
29 Correct 5 ms 16988 KB Output is correct
30 Correct 7 ms 17480 KB Output is correct
31 Correct 5 ms 16984 KB Output is correct
32 Correct 5 ms 16988 KB Output is correct
33 Correct 5 ms 16988 KB Output is correct
34 Correct 5 ms 16988 KB Output is correct
35 Correct 7 ms 16988 KB Output is correct
36 Correct 6 ms 17240 KB Output is correct
37 Correct 6 ms 17244 KB Output is correct
38 Correct 6 ms 17244 KB Output is correct
39 Correct 5 ms 16988 KB Output is correct
40 Correct 5 ms 16988 KB Output is correct
41 Correct 5 ms 17016 KB Output is correct
42 Correct 6 ms 16988 KB Output is correct
43 Correct 5 ms 16984 KB Output is correct
44 Correct 5 ms 17112 KB Output is correct
45 Correct 5 ms 16988 KB Output is correct
46 Correct 7 ms 17136 KB Output is correct
47 Correct 5 ms 16988 KB Output is correct
48 Correct 5 ms 16988 KB Output is correct
49 Correct 6 ms 16988 KB Output is correct
50 Correct 6 ms 16988 KB Output is correct
51 Correct 5 ms 16988 KB Output is correct
52 Correct 6 ms 16988 KB Output is correct
53 Correct 5 ms 16988 KB Output is correct
54 Correct 6 ms 17208 KB Output is correct
55 Correct 205 ms 39352 KB Output is correct
56 Correct 306 ms 50048 KB Output is correct
57 Correct 193 ms 50536 KB Output is correct
58 Correct 227 ms 41580 KB Output is correct
59 Correct 250 ms 41916 KB Output is correct
60 Correct 265 ms 41916 KB Output is correct
61 Correct 212 ms 40636 KB Output is correct
62 Correct 241 ms 41912 KB Output is correct
63 Correct 218 ms 41144 KB Output is correct
64 Correct 252 ms 42432 KB Output is correct
65 Correct 263 ms 41660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16732 KB Output is correct
2 Correct 3 ms 16732 KB Output is correct
3 Correct 3 ms 16728 KB Output is correct
4 Correct 3 ms 16728 KB Output is correct
5 Correct 3 ms 16732 KB Output is correct
6 Correct 3 ms 16732 KB Output is correct
7 Correct 3 ms 16900 KB Output is correct
8 Correct 3 ms 16732 KB Output is correct
9 Correct 4 ms 16816 KB Output is correct
10 Correct 3 ms 16732 KB Output is correct
11 Correct 3 ms 16732 KB Output is correct
12 Correct 4 ms 16732 KB Output is correct
13 Correct 4 ms 16728 KB Output is correct
14 Correct 3 ms 16732 KB Output is correct
15 Correct 3 ms 16732 KB Output is correct
16 Correct 3 ms 16732 KB Output is correct
17 Correct 3 ms 16728 KB Output is correct
18 Correct 3 ms 16732 KB Output is correct
19 Correct 4 ms 16732 KB Output is correct
20 Correct 3 ms 16732 KB Output is correct
21 Correct 3 ms 16732 KB Output is correct
22 Correct 4 ms 16732 KB Output is correct
23 Correct 3 ms 16732 KB Output is correct
24 Correct 4 ms 16732 KB Output is correct
25 Correct 4 ms 16732 KB Output is correct
26 Correct 3 ms 16728 KB Output is correct
27 Correct 3 ms 16732 KB Output is correct
28 Correct 3 ms 16732 KB Output is correct
29 Correct 5 ms 16988 KB Output is correct
30 Correct 7 ms 17480 KB Output is correct
31 Correct 5 ms 16984 KB Output is correct
32 Correct 5 ms 16988 KB Output is correct
33 Correct 5 ms 16988 KB Output is correct
34 Correct 5 ms 16988 KB Output is correct
35 Correct 7 ms 16988 KB Output is correct
36 Correct 6 ms 17240 KB Output is correct
37 Correct 6 ms 17244 KB Output is correct
38 Correct 6 ms 17244 KB Output is correct
39 Correct 5 ms 16988 KB Output is correct
40 Correct 5 ms 16988 KB Output is correct
41 Correct 5 ms 17016 KB Output is correct
42 Correct 6 ms 16988 KB Output is correct
43 Correct 5 ms 16984 KB Output is correct
44 Correct 5 ms 17112 KB Output is correct
45 Correct 5 ms 16988 KB Output is correct
46 Correct 7 ms 17136 KB Output is correct
47 Correct 5 ms 16988 KB Output is correct
48 Correct 5 ms 16988 KB Output is correct
49 Correct 6 ms 16988 KB Output is correct
50 Correct 6 ms 16988 KB Output is correct
51 Correct 5 ms 16988 KB Output is correct
52 Correct 6 ms 16988 KB Output is correct
53 Correct 5 ms 16988 KB Output is correct
54 Correct 6 ms 17208 KB Output is correct
55 Correct 227 ms 39604 KB Output is correct
56 Correct 331 ms 50616 KB Output is correct
57 Correct 187 ms 49800 KB Output is correct
58 Correct 253 ms 41900 KB Output is correct
59 Correct 255 ms 41256 KB Output is correct
60 Correct 249 ms 40636 KB Output is correct
61 Correct 262 ms 40900 KB Output is correct
62 Correct 301 ms 50212 KB Output is correct
63 Correct 237 ms 41920 KB Output is correct
64 Correct 255 ms 43200 KB Output is correct
65 Correct 219 ms 38384 KB Output is correct
66 Correct 312 ms 42176 KB Output is correct
67 Correct 285 ms 42092 KB Output is correct
68 Correct 296 ms 50596 KB Output is correct
69 Correct 226 ms 42988 KB Output is correct
70 Correct 330 ms 51380 KB Output is correct
71 Correct 355 ms 51160 KB Output is correct
72 Correct 251 ms 41652 KB Output is correct
73 Correct 257 ms 42884 KB Output is correct
74 Correct 268 ms 41656 KB Output is correct
75 Correct 294 ms 51128 KB Output is correct
76 Correct 238 ms 42076 KB Output is correct
77 Correct 248 ms 42804 KB Output is correct
78 Correct 259 ms 49592 KB Output is correct
79 Correct 227 ms 38464 KB Output is correct
80 Correct 288 ms 41748 KB Output is correct
81 Correct 317 ms 43416 KB Output is correct
82 Correct 292 ms 51132 KB Output is correct
83 Correct 205 ms 39352 KB Output is correct
84 Correct 306 ms 50048 KB Output is correct
85 Correct 193 ms 50536 KB Output is correct
86 Correct 227 ms 41580 KB Output is correct
87 Correct 250 ms 41916 KB Output is correct
88 Correct 265 ms 41916 KB Output is correct
89 Correct 212 ms 40636 KB Output is correct
90 Correct 241 ms 41912 KB Output is correct
91 Correct 218 ms 41144 KB Output is correct
92 Correct 252 ms 42432 KB Output is correct
93 Correct 263 ms 41660 KB Output is correct
94 Correct 229 ms 42932 KB Output is correct
95 Correct 263 ms 49840 KB Output is correct
96 Correct 193 ms 49852 KB Output is correct
97 Correct 258 ms 42216 KB Output is correct
98 Correct 286 ms 42512 KB Output is correct
99 Correct 257 ms 42416 KB Output is correct
100 Correct 297 ms 50352 KB Output is correct
101 Correct 233 ms 42428 KB Output is correct
102 Correct 255 ms 43188 KB Output is correct
103 Correct 289 ms 50876 KB Output is correct
104 Correct 250 ms 41140 KB Output is correct
105 Correct 285 ms 42964 KB Output is correct
106 Correct 302 ms 44320 KB Output is correct
107 Correct 328 ms 50796 KB Output is correct
108 Correct 228 ms 42672 KB Output is correct
109 Correct 236 ms 43712 KB Output is correct
110 Correct 228 ms 42932 KB Output is correct
111 Correct 230 ms 42032 KB Output is correct
112 Correct 236 ms 43588 KB Output is correct
113 Correct 229 ms 42032 KB Output is correct
114 Correct 227 ms 43032 KB Output is correct
115 Correct 229 ms 41904 KB Output is correct
116 Correct 230 ms 42820 KB Output is correct