Submission #561837

# Submission time Handle Problem Language Result Execution time Memory
561837 2022-05-13T15:54:41 Z Sohsoh84 Joker (BOI20_joker) C++17
100 / 100
316 ms 18260 KB
#include <bits/stdc++.h>

using namespace std;

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

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e6 + 10;

int C[MAXN], par[MAXN], sz[MAXN], opt[MAXN], n, m, q, shit;
stack<pll> hist;
pll E[MAXN];
bool flag;

pll find(int v) {
	if (v == par[v]) return {v, 0};
	pll ans = find(par[v]);
	ans.Y ^= C[v];
	return ans;
}

inline int unite(int ind) {
	int u = E[ind].X, v = E[ind].Y;
	int cu, cv;
	tie(u, cu) = find(u);
	tie(v, cv) = find(v);

	if (v == u) {
		if (cv != cu) {
			hist.push({-2, -2});
			return 2;
		} else { 
			hist.push({-1, -1});
			shit++;
			return 1;
		}
	}

	if (sz[u] < sz[v]) swap(v, u);
	par[v] = u;
	sz[u] += sz[v];
	C[v] = cv ^ cu ^ 1;
	hist.push({v, u});
	return 0;
}

inline void rollback(int cnt) {
	while (cnt > 0 && !hist.empty()) {
		int v = hist.top().X, u = hist.top().Y;
		cnt--;
	
		hist.pop();
		if (v == -1) shit--;
		if (v < 0) continue;
		
		par[v] = v;
		sz[u] -= sz[v];
		C[v] = 0;
	}
}

void solve(int l = 1, int r = m, int optl = 0, int optr = m + 1) {
	if (r < l) return;
	int mid = (l + r) >> 1;

	for (int i = l; i < mid; i++)
		unite(i);

	// min, max -> opt
	
	if (shit) opt[mid] = optr; // +1 ? fd 
	else {
		opt[mid] = optr;
		while (opt[mid] >= optl) {
			if (unite(opt[mid]) == 1) {
				rollback(1);
				break;
			}

			opt[mid]--;
		}

		if (opt[mid] < optl) flag = true;
	}

	rollback(optr - opt[mid]);
	unite(mid);
	solve(mid + 1, r, opt[mid], optr);
	
	rollback(mid - l + 1);
	for (int i = opt[mid] + 1; i <= optr; i++)
		unite(i);
	
	solve(l, mid - 1, optl, opt[mid]);
	rollback(optr - opt[mid]);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);	
	cin >> n >> m >> q;
	for (int i = 0; i < MAXN; i++) {
		par[i] = i;
		sz[i] = 1;
	}

	for (int i = 1; i <= m; i++)
		cin >> E[i].X >> E[i].Y;

	E[m + 1] = {MAXN - 1, MAXN - 2};
	solve();

	while (q--) {
		int l, r;
		cin >> l >> r;
		cout << (flag || r >= opt[l] ? "NO" : "YES") << endl;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 6 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 4 ms 8148 KB Output is correct
7 Correct 4 ms 8144 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 5 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 4 ms 8148 KB Output is correct
15 Correct 5 ms 8104 KB Output is correct
16 Correct 5 ms 8144 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 5 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 6 ms 8152 KB Output is correct
21 Correct 4 ms 8148 KB Output is correct
22 Correct 6 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 4 ms 8140 KB Output is correct
25 Correct 4 ms 8148 KB Output is correct
26 Correct 5 ms 8076 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 6 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 6 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 4 ms 8148 KB Output is correct
7 Correct 4 ms 8144 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 5 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 4 ms 8148 KB Output is correct
15 Correct 5 ms 8104 KB Output is correct
16 Correct 5 ms 8144 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 5 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 6 ms 8152 KB Output is correct
21 Correct 4 ms 8148 KB Output is correct
22 Correct 6 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 4 ms 8140 KB Output is correct
25 Correct 4 ms 8148 KB Output is correct
26 Correct 5 ms 8076 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 6 ms 8148 KB Output is correct
29 Correct 11 ms 8168 KB Output is correct
30 Correct 6 ms 8220 KB Output is correct
31 Correct 7 ms 8160 KB Output is correct
32 Correct 7 ms 8240 KB Output is correct
33 Correct 6 ms 8148 KB Output is correct
34 Correct 7 ms 8148 KB Output is correct
35 Correct 7 ms 8148 KB Output is correct
36 Correct 6 ms 8204 KB Output is correct
37 Correct 6 ms 8264 KB Output is correct
38 Correct 8 ms 8276 KB Output is correct
39 Correct 6 ms 8148 KB Output is correct
40 Correct 7 ms 8204 KB Output is correct
41 Correct 5 ms 8148 KB Output is correct
42 Correct 8 ms 8148 KB Output is correct
43 Correct 6 ms 8260 KB Output is correct
44 Correct 6 ms 8140 KB Output is correct
45 Correct 6 ms 8260 KB Output is correct
46 Correct 6 ms 8160 KB Output is correct
47 Correct 7 ms 8160 KB Output is correct
48 Correct 6 ms 8148 KB Output is correct
49 Correct 6 ms 8148 KB Output is correct
50 Correct 8 ms 8148 KB Output is correct
51 Correct 8 ms 8252 KB Output is correct
52 Correct 6 ms 8148 KB Output is correct
53 Correct 6 ms 8148 KB Output is correct
54 Correct 7 ms 8160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 168 ms 16608 KB Output is correct
4 Correct 273 ms 17468 KB Output is correct
5 Correct 151 ms 17176 KB Output is correct
6 Correct 211 ms 16556 KB Output is correct
7 Correct 178 ms 16544 KB Output is correct
8 Correct 194 ms 15816 KB Output is correct
9 Correct 223 ms 16004 KB Output is correct
10 Correct 273 ms 16684 KB Output is correct
11 Correct 209 ms 16512 KB Output is correct
12 Correct 220 ms 17000 KB Output is correct
13 Correct 213 ms 16092 KB Output is correct
14 Correct 205 ms 16384 KB Output is correct
15 Correct 258 ms 16724 KB Output is correct
16 Correct 289 ms 17028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 6 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 4 ms 8148 KB Output is correct
7 Correct 4 ms 8144 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 5 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 4 ms 8148 KB Output is correct
15 Correct 5 ms 8104 KB Output is correct
16 Correct 5 ms 8144 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 5 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 6 ms 8152 KB Output is correct
21 Correct 4 ms 8148 KB Output is correct
22 Correct 6 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 4 ms 8140 KB Output is correct
25 Correct 4 ms 8148 KB Output is correct
26 Correct 5 ms 8076 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 6 ms 8148 KB Output is correct
29 Correct 168 ms 16608 KB Output is correct
30 Correct 273 ms 17468 KB Output is correct
31 Correct 151 ms 17176 KB Output is correct
32 Correct 211 ms 16556 KB Output is correct
33 Correct 178 ms 16544 KB Output is correct
34 Correct 194 ms 15816 KB Output is correct
35 Correct 223 ms 16004 KB Output is correct
36 Correct 273 ms 16684 KB Output is correct
37 Correct 209 ms 16512 KB Output is correct
38 Correct 220 ms 17000 KB Output is correct
39 Correct 213 ms 16092 KB Output is correct
40 Correct 205 ms 16384 KB Output is correct
41 Correct 258 ms 16724 KB Output is correct
42 Correct 289 ms 17028 KB Output is correct
43 Correct 172 ms 16800 KB Output is correct
44 Correct 260 ms 17816 KB Output is correct
45 Correct 235 ms 17248 KB Output is correct
46 Correct 175 ms 16848 KB Output is correct
47 Correct 199 ms 16928 KB Output is correct
48 Correct 226 ms 16496 KB Output is correct
49 Correct 284 ms 17224 KB Output is correct
50 Correct 208 ms 16676 KB Output is correct
51 Correct 220 ms 17072 KB Output is correct
52 Correct 244 ms 17300 KB Output is correct
53 Correct 197 ms 16368 KB Output is correct
54 Correct 243 ms 16740 KB Output is correct
55 Correct 256 ms 17124 KB Output is correct
56 Correct 316 ms 17268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 6 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 4 ms 8148 KB Output is correct
7 Correct 4 ms 8144 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 5 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 4 ms 8148 KB Output is correct
15 Correct 5 ms 8104 KB Output is correct
16 Correct 5 ms 8144 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 5 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 6 ms 8152 KB Output is correct
21 Correct 4 ms 8148 KB Output is correct
22 Correct 6 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 4 ms 8140 KB Output is correct
25 Correct 4 ms 8148 KB Output is correct
26 Correct 5 ms 8076 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 6 ms 8148 KB Output is correct
29 Correct 11 ms 8168 KB Output is correct
30 Correct 6 ms 8220 KB Output is correct
31 Correct 7 ms 8160 KB Output is correct
32 Correct 7 ms 8240 KB Output is correct
33 Correct 6 ms 8148 KB Output is correct
34 Correct 7 ms 8148 KB Output is correct
35 Correct 7 ms 8148 KB Output is correct
36 Correct 6 ms 8204 KB Output is correct
37 Correct 6 ms 8264 KB Output is correct
38 Correct 8 ms 8276 KB Output is correct
39 Correct 6 ms 8148 KB Output is correct
40 Correct 7 ms 8204 KB Output is correct
41 Correct 5 ms 8148 KB Output is correct
42 Correct 8 ms 8148 KB Output is correct
43 Correct 6 ms 8260 KB Output is correct
44 Correct 6 ms 8140 KB Output is correct
45 Correct 6 ms 8260 KB Output is correct
46 Correct 6 ms 8160 KB Output is correct
47 Correct 7 ms 8160 KB Output is correct
48 Correct 6 ms 8148 KB Output is correct
49 Correct 6 ms 8148 KB Output is correct
50 Correct 8 ms 8148 KB Output is correct
51 Correct 8 ms 8252 KB Output is correct
52 Correct 6 ms 8148 KB Output is correct
53 Correct 6 ms 8148 KB Output is correct
54 Correct 7 ms 8160 KB Output is correct
55 Correct 151 ms 14244 KB Output is correct
56 Correct 267 ms 16456 KB Output is correct
57 Correct 110 ms 14796 KB Output is correct
58 Correct 139 ms 14284 KB Output is correct
59 Correct 201 ms 14212 KB Output is correct
60 Correct 229 ms 14660 KB Output is correct
61 Correct 201 ms 14408 KB Output is correct
62 Correct 187 ms 14760 KB Output is correct
63 Correct 156 ms 13996 KB Output is correct
64 Correct 221 ms 14392 KB Output is correct
65 Correct 231 ms 14756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 6 ms 8148 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 4 ms 8148 KB Output is correct
7 Correct 4 ms 8144 KB Output is correct
8 Correct 4 ms 8148 KB Output is correct
9 Correct 4 ms 8148 KB Output is correct
10 Correct 4 ms 8148 KB Output is correct
11 Correct 4 ms 8148 KB Output is correct
12 Correct 5 ms 8148 KB Output is correct
13 Correct 5 ms 8148 KB Output is correct
14 Correct 4 ms 8148 KB Output is correct
15 Correct 5 ms 8104 KB Output is correct
16 Correct 5 ms 8144 KB Output is correct
17 Correct 4 ms 8148 KB Output is correct
18 Correct 5 ms 8148 KB Output is correct
19 Correct 5 ms 8148 KB Output is correct
20 Correct 6 ms 8152 KB Output is correct
21 Correct 4 ms 8148 KB Output is correct
22 Correct 6 ms 8148 KB Output is correct
23 Correct 4 ms 8148 KB Output is correct
24 Correct 4 ms 8140 KB Output is correct
25 Correct 4 ms 8148 KB Output is correct
26 Correct 5 ms 8076 KB Output is correct
27 Correct 5 ms 8148 KB Output is correct
28 Correct 6 ms 8148 KB Output is correct
29 Correct 11 ms 8168 KB Output is correct
30 Correct 6 ms 8220 KB Output is correct
31 Correct 7 ms 8160 KB Output is correct
32 Correct 7 ms 8240 KB Output is correct
33 Correct 6 ms 8148 KB Output is correct
34 Correct 7 ms 8148 KB Output is correct
35 Correct 7 ms 8148 KB Output is correct
36 Correct 6 ms 8204 KB Output is correct
37 Correct 6 ms 8264 KB Output is correct
38 Correct 8 ms 8276 KB Output is correct
39 Correct 6 ms 8148 KB Output is correct
40 Correct 7 ms 8204 KB Output is correct
41 Correct 5 ms 8148 KB Output is correct
42 Correct 8 ms 8148 KB Output is correct
43 Correct 6 ms 8260 KB Output is correct
44 Correct 6 ms 8140 KB Output is correct
45 Correct 6 ms 8260 KB Output is correct
46 Correct 6 ms 8160 KB Output is correct
47 Correct 7 ms 8160 KB Output is correct
48 Correct 6 ms 8148 KB Output is correct
49 Correct 6 ms 8148 KB Output is correct
50 Correct 8 ms 8148 KB Output is correct
51 Correct 8 ms 8252 KB Output is correct
52 Correct 6 ms 8148 KB Output is correct
53 Correct 6 ms 8148 KB Output is correct
54 Correct 7 ms 8160 KB Output is correct
55 Correct 168 ms 16608 KB Output is correct
56 Correct 273 ms 17468 KB Output is correct
57 Correct 151 ms 17176 KB Output is correct
58 Correct 211 ms 16556 KB Output is correct
59 Correct 178 ms 16544 KB Output is correct
60 Correct 194 ms 15816 KB Output is correct
61 Correct 223 ms 16004 KB Output is correct
62 Correct 273 ms 16684 KB Output is correct
63 Correct 209 ms 16512 KB Output is correct
64 Correct 220 ms 17000 KB Output is correct
65 Correct 213 ms 16092 KB Output is correct
66 Correct 205 ms 16384 KB Output is correct
67 Correct 258 ms 16724 KB Output is correct
68 Correct 289 ms 17028 KB Output is correct
69 Correct 172 ms 16800 KB Output is correct
70 Correct 260 ms 17816 KB Output is correct
71 Correct 235 ms 17248 KB Output is correct
72 Correct 175 ms 16848 KB Output is correct
73 Correct 199 ms 16928 KB Output is correct
74 Correct 226 ms 16496 KB Output is correct
75 Correct 284 ms 17224 KB Output is correct
76 Correct 208 ms 16676 KB Output is correct
77 Correct 220 ms 17072 KB Output is correct
78 Correct 244 ms 17300 KB Output is correct
79 Correct 197 ms 16368 KB Output is correct
80 Correct 243 ms 16740 KB Output is correct
81 Correct 256 ms 17124 KB Output is correct
82 Correct 316 ms 17268 KB Output is correct
83 Correct 151 ms 14244 KB Output is correct
84 Correct 267 ms 16456 KB Output is correct
85 Correct 110 ms 14796 KB Output is correct
86 Correct 139 ms 14284 KB Output is correct
87 Correct 201 ms 14212 KB Output is correct
88 Correct 229 ms 14660 KB Output is correct
89 Correct 201 ms 14408 KB Output is correct
90 Correct 187 ms 14760 KB Output is correct
91 Correct 156 ms 13996 KB Output is correct
92 Correct 221 ms 14392 KB Output is correct
93 Correct 231 ms 14756 KB Output is correct
94 Correct 184 ms 17656 KB Output is correct
95 Correct 230 ms 17948 KB Output is correct
96 Correct 159 ms 17952 KB Output is correct
97 Correct 220 ms 17504 KB Output is correct
98 Correct 207 ms 17536 KB Output is correct
99 Correct 232 ms 17348 KB Output is correct
100 Correct 254 ms 18224 KB Output is correct
101 Correct 206 ms 17448 KB Output is correct
102 Correct 246 ms 17780 KB Output is correct
103 Correct 251 ms 18080 KB Output is correct
104 Correct 220 ms 17248 KB Output is correct
105 Correct 245 ms 17784 KB Output is correct
106 Correct 301 ms 18004 KB Output is correct
107 Correct 134 ms 18260 KB Output is correct
108 Correct 180 ms 17384 KB Output is correct
109 Correct 192 ms 17356 KB Output is correct
110 Correct 186 ms 17396 KB Output is correct
111 Correct 189 ms 17280 KB Output is correct
112 Correct 184 ms 17292 KB Output is correct
113 Correct 215 ms 17420 KB Output is correct
114 Correct 172 ms 17276 KB Output is correct
115 Correct 204 ms 17288 KB Output is correct
116 Correct 185 ms 17324 KB Output is correct