Submission #810472

# Submission time Handle Problem Language Result Execution time Memory
810472 2023-08-06T10:02:51 Z ymm Joker (BOI20_joker) C++17
100 / 100
212 ms 13756 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
typedef std::pair<int,int> pii;
typedef long long ll;
using namespace std;

const int N = 200'010;

namespace dsu {
	int par[N];
	int sz[N];
	bool parpar[N];

	void init() { fill(par, par+N, -1); fill(sz, sz+N, 1); }
	pii rt(int v) {
		int p = 0;
		while (par[v] != -1) {
			p ^= parpar[v];
			v = par[v];
		}
		return {v, p};
	}
	bool can(int v, int u) {
		auto [x1, y1] = rt(v);
		auto [x2, y2] = rt(u);
		return x1 != x2 || y1 != y2;
	}
	vector<pii> his;
	bool unite(int v, int u) {
		auto [x1, y1] = rt(v);
		auto [x2, y2] = rt(u);
		if (x1 == x2) {
			if (y1 == y2)
				return 0;
			his.push_back({-1, -1});
			return 1;
		}
		if (sz[x1] < sz[x2]) {
			swap(x1, x2);
			swap(y1, y2);
		}
		par[x2] = x1;
		parpar[x2] = 1 ^ y1 ^ y2;
		sz[x1] += sz[x2];
		his.emplace_back(x1, x2);
		return 1;
	}
	void undo() {
		auto [x1, x2] = his.back();
		his.pop_back();
		if (x2 == -1)
			return;
		sz[x1] -= sz[x2];
		par[x2] = -1;
	}
}

pii E[N];
bool unite(int i) { return dsu::unite(E[i].first, E[i].second); }

int L, R;
vector<int> dir;

void undo() {
	dsu::undo();
	if (dir.back() == 0)
		--L;
	else
		++R;
	dir.pop_back();
}

bool mov(int l, int r)
{
	if (l > r)
		return 0;
	while (l < L)
		undo();
	while (R < r)
		undo();
	while (L < l) {
		if (!unite(L))
			return 0;
		dir.push_back(0);
		++L;
	}
	while (r < R) {
		if (!unite(R-1))
			return 0;
		dir.push_back(1);
		--R;
	}
	return 1;
}

int mn_ac[N];

void dc(int l1, int r1, int l2, int r2)
{
	if (l1 >= r1)
		return;
	//cerr << l1 << ' ' << r1 << " -> " << l2 << ' ' << r2 << '\n';
	int m = (l1 + r1)/2;
	mov(l1, r2-1);
	if (!mov(m, r2-1)) {
		Loop (i,m,r1)
			mn_ac[i] = N;
		dc(l1, m, l2, r2);
		return;
	}
	while (mov(m, R-1));
	int ans = R;
	mn_ac[m] = ans;
	//cerr << "mn[" << m << "] = " << ans << '\n';
	dc(l1, m, l2, ans+1);
	dc(m+1, r1, ans, r2);
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	int n, m, q;
	cin >> n >> m >> q;
	dsu::init();
	L = 0;
	R = m;
	Loop (i,0,m) {
		int v, u;
		cin >> v >> u;
		E[i] = {v, u};
	}
	dc(0, m+1, 0, m+1);
	Loop (i,0,q) {
		int l, r;
		cin >> l >> r;
		--l;
		if (r >= mn_ac[l])
		//if (mov(l, r))
			cout << "NO\n";
		else
			cout << "YES\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 2 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 2 ms 1876 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 2 ms 1876 KB Output is correct
31 Correct 2 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 2 ms 1876 KB Output is correct
34 Correct 2 ms 1876 KB Output is correct
35 Correct 2 ms 1876 KB Output is correct
36 Correct 2 ms 1876 KB Output is correct
37 Correct 2 ms 1876 KB Output is correct
38 Correct 2 ms 1876 KB Output is correct
39 Correct 2 ms 1876 KB Output is correct
40 Correct 2 ms 1876 KB Output is correct
41 Correct 2 ms 1928 KB Output is correct
42 Correct 1 ms 1876 KB Output is correct
43 Correct 2 ms 1876 KB Output is correct
44 Correct 3 ms 1876 KB Output is correct
45 Correct 2 ms 1876 KB Output is correct
46 Correct 2 ms 1876 KB Output is correct
47 Correct 2 ms 1876 KB Output is correct
48 Correct 2 ms 1876 KB Output is correct
49 Correct 3 ms 1876 KB Output is correct
50 Correct 2 ms 1876 KB Output is correct
51 Correct 2 ms 1944 KB Output is correct
52 Correct 2 ms 1876 KB Output is correct
53 Correct 2 ms 1876 KB Output is correct
54 Correct 2 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 114 ms 6556 KB Output is correct
4 Correct 210 ms 8336 KB Output is correct
5 Correct 111 ms 8184 KB Output is correct
6 Correct 90 ms 6576 KB Output is correct
7 Correct 88 ms 6560 KB Output is correct
8 Correct 119 ms 6692 KB Output is correct
9 Correct 118 ms 6732 KB Output is correct
10 Correct 154 ms 6808 KB Output is correct
11 Correct 128 ms 6584 KB Output is correct
12 Correct 123 ms 6816 KB Output is correct
13 Correct 123 ms 6572 KB Output is correct
14 Correct 121 ms 6540 KB Output is correct
15 Correct 146 ms 6656 KB Output is correct
16 Correct 157 ms 6720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 2 ms 1876 KB Output is correct
29 Correct 114 ms 6556 KB Output is correct
30 Correct 210 ms 8336 KB Output is correct
31 Correct 111 ms 8184 KB Output is correct
32 Correct 90 ms 6576 KB Output is correct
33 Correct 88 ms 6560 KB Output is correct
34 Correct 119 ms 6692 KB Output is correct
35 Correct 118 ms 6732 KB Output is correct
36 Correct 154 ms 6808 KB Output is correct
37 Correct 128 ms 6584 KB Output is correct
38 Correct 123 ms 6816 KB Output is correct
39 Correct 123 ms 6572 KB Output is correct
40 Correct 121 ms 6540 KB Output is correct
41 Correct 146 ms 6656 KB Output is correct
42 Correct 157 ms 6720 KB Output is correct
43 Correct 129 ms 10888 KB Output is correct
44 Correct 209 ms 12380 KB Output is correct
45 Correct 179 ms 12816 KB Output is correct
46 Correct 97 ms 10928 KB Output is correct
47 Correct 93 ms 10892 KB Output is correct
48 Correct 130 ms 10568 KB Output is correct
49 Correct 159 ms 10976 KB Output is correct
50 Correct 129 ms 10824 KB Output is correct
51 Correct 131 ms 11056 KB Output is correct
52 Correct 127 ms 11116 KB Output is correct
53 Correct 113 ms 10624 KB Output is correct
54 Correct 134 ms 10956 KB Output is correct
55 Correct 142 ms 11048 KB Output is correct
56 Correct 212 ms 11116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 2 ms 1876 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 2 ms 1876 KB Output is correct
31 Correct 2 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 2 ms 1876 KB Output is correct
34 Correct 2 ms 1876 KB Output is correct
35 Correct 2 ms 1876 KB Output is correct
36 Correct 2 ms 1876 KB Output is correct
37 Correct 2 ms 1876 KB Output is correct
38 Correct 2 ms 1876 KB Output is correct
39 Correct 2 ms 1876 KB Output is correct
40 Correct 2 ms 1876 KB Output is correct
41 Correct 2 ms 1928 KB Output is correct
42 Correct 1 ms 1876 KB Output is correct
43 Correct 2 ms 1876 KB Output is correct
44 Correct 3 ms 1876 KB Output is correct
45 Correct 2 ms 1876 KB Output is correct
46 Correct 2 ms 1876 KB Output is correct
47 Correct 2 ms 1876 KB Output is correct
48 Correct 2 ms 1876 KB Output is correct
49 Correct 3 ms 1876 KB Output is correct
50 Correct 2 ms 1876 KB Output is correct
51 Correct 2 ms 1944 KB Output is correct
52 Correct 2 ms 1876 KB Output is correct
53 Correct 2 ms 1876 KB Output is correct
54 Correct 2 ms 1876 KB Output is correct
55 Correct 83 ms 5952 KB Output is correct
56 Correct 179 ms 7804 KB Output is correct
57 Correct 74 ms 10040 KB Output is correct
58 Correct 70 ms 8360 KB Output is correct
59 Correct 101 ms 8304 KB Output is correct
60 Correct 129 ms 8532 KB Output is correct
61 Correct 120 ms 8272 KB Output is correct
62 Correct 112 ms 8632 KB Output is correct
63 Correct 91 ms 8136 KB Output is correct
64 Correct 128 ms 8452 KB Output is correct
65 Correct 131 ms 8592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 1 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 2 ms 1876 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 2 ms 1876 KB Output is correct
31 Correct 2 ms 1876 KB Output is correct
32 Correct 2 ms 1876 KB Output is correct
33 Correct 2 ms 1876 KB Output is correct
34 Correct 2 ms 1876 KB Output is correct
35 Correct 2 ms 1876 KB Output is correct
36 Correct 2 ms 1876 KB Output is correct
37 Correct 2 ms 1876 KB Output is correct
38 Correct 2 ms 1876 KB Output is correct
39 Correct 2 ms 1876 KB Output is correct
40 Correct 2 ms 1876 KB Output is correct
41 Correct 2 ms 1928 KB Output is correct
42 Correct 1 ms 1876 KB Output is correct
43 Correct 2 ms 1876 KB Output is correct
44 Correct 3 ms 1876 KB Output is correct
45 Correct 2 ms 1876 KB Output is correct
46 Correct 2 ms 1876 KB Output is correct
47 Correct 2 ms 1876 KB Output is correct
48 Correct 2 ms 1876 KB Output is correct
49 Correct 3 ms 1876 KB Output is correct
50 Correct 2 ms 1876 KB Output is correct
51 Correct 2 ms 1944 KB Output is correct
52 Correct 2 ms 1876 KB Output is correct
53 Correct 2 ms 1876 KB Output is correct
54 Correct 2 ms 1876 KB Output is correct
55 Correct 114 ms 6556 KB Output is correct
56 Correct 210 ms 8336 KB Output is correct
57 Correct 111 ms 8184 KB Output is correct
58 Correct 90 ms 6576 KB Output is correct
59 Correct 88 ms 6560 KB Output is correct
60 Correct 119 ms 6692 KB Output is correct
61 Correct 118 ms 6732 KB Output is correct
62 Correct 154 ms 6808 KB Output is correct
63 Correct 128 ms 6584 KB Output is correct
64 Correct 123 ms 6816 KB Output is correct
65 Correct 123 ms 6572 KB Output is correct
66 Correct 121 ms 6540 KB Output is correct
67 Correct 146 ms 6656 KB Output is correct
68 Correct 157 ms 6720 KB Output is correct
69 Correct 129 ms 10888 KB Output is correct
70 Correct 209 ms 12380 KB Output is correct
71 Correct 179 ms 12816 KB Output is correct
72 Correct 97 ms 10928 KB Output is correct
73 Correct 93 ms 10892 KB Output is correct
74 Correct 130 ms 10568 KB Output is correct
75 Correct 159 ms 10976 KB Output is correct
76 Correct 129 ms 10824 KB Output is correct
77 Correct 131 ms 11056 KB Output is correct
78 Correct 127 ms 11116 KB Output is correct
79 Correct 113 ms 10624 KB Output is correct
80 Correct 134 ms 10956 KB Output is correct
81 Correct 142 ms 11048 KB Output is correct
82 Correct 212 ms 11116 KB Output is correct
83 Correct 83 ms 5952 KB Output is correct
84 Correct 179 ms 7804 KB Output is correct
85 Correct 74 ms 10040 KB Output is correct
86 Correct 70 ms 8360 KB Output is correct
87 Correct 101 ms 8304 KB Output is correct
88 Correct 129 ms 8532 KB Output is correct
89 Correct 120 ms 8272 KB Output is correct
90 Correct 112 ms 8632 KB Output is correct
91 Correct 91 ms 8136 KB Output is correct
92 Correct 128 ms 8452 KB Output is correct
93 Correct 131 ms 8592 KB Output is correct
94 Correct 116 ms 11608 KB Output is correct
95 Correct 159 ms 13456 KB Output is correct
96 Correct 103 ms 13348 KB Output is correct
97 Correct 89 ms 11688 KB Output is correct
98 Correct 91 ms 11604 KB Output is correct
99 Correct 116 ms 11560 KB Output is correct
100 Correct 138 ms 12092 KB Output is correct
101 Correct 130 ms 11636 KB Output is correct
102 Correct 145 ms 11844 KB Output is correct
103 Correct 143 ms 12116 KB Output is correct
104 Correct 117 ms 11504 KB Output is correct
105 Correct 146 ms 11708 KB Output is correct
106 Correct 161 ms 11856 KB Output is correct
107 Correct 82 ms 13756 KB Output is correct
108 Correct 112 ms 11352 KB Output is correct
109 Correct 120 ms 11456 KB Output is correct
110 Correct 111 ms 11352 KB Output is correct
111 Correct 122 ms 11460 KB Output is correct
112 Correct 114 ms 11436 KB Output is correct
113 Correct 116 ms 11496 KB Output is correct
114 Correct 112 ms 11452 KB Output is correct
115 Correct 112 ms 11420 KB Output is correct
116 Correct 113 ms 11344 KB Output is correct