답안 #810451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
810451 2023-08-06T09:54:29 Z ymm Joker (BOI20_joker) C++17
14 / 100
2000 ms 10356 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, l1, 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";
	}
}
# 결과 실행 시간 메모리 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 1 ms 1872 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 1 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 1 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 1916 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 1880 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 1 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 1872 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 1 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 1 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 1916 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 1880 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 1 ms 1876 KB Output is correct
29 Correct 17 ms 1952 KB Output is correct
30 Correct 14 ms 1992 KB Output is correct
31 Correct 12 ms 1976 KB Output is correct
32 Correct 6 ms 1976 KB Output is correct
33 Correct 3 ms 1876 KB Output is correct
34 Correct 9 ms 1876 KB Output is correct
35 Correct 17 ms 1956 KB Output is correct
36 Correct 7 ms 1876 KB Output is correct
37 Correct 20 ms 1984 KB Output is correct
38 Correct 26 ms 1988 KB Output is correct
39 Correct 11 ms 1996 KB Output is correct
40 Correct 6 ms 1876 KB Output is correct
41 Correct 6 ms 1892 KB Output is correct
42 Correct 6 ms 1888 KB Output is correct
43 Correct 3 ms 1876 KB Output is correct
44 Correct 6 ms 1876 KB Output is correct
45 Correct 6 ms 1876 KB Output is correct
46 Correct 14 ms 1876 KB Output is correct
47 Correct 9 ms 1984 KB Output is correct
48 Correct 9 ms 1876 KB Output is correct
49 Correct 11 ms 1988 KB Output is correct
50 Correct 12 ms 2004 KB Output is correct
51 Correct 7 ms 1876 KB Output is correct
52 Correct 9 ms 1976 KB Output is correct
53 Correct 11 ms 1944 KB Output is correct
54 Correct 15 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Execution timed out 2078 ms 5608 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 1872 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 1 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 1 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 1916 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 1880 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 1 ms 1876 KB Output is correct
29 Execution timed out 2078 ms 5608 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 1872 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 1 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 1 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 1916 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 1880 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 1 ms 1876 KB Output is correct
29 Correct 17 ms 1952 KB Output is correct
30 Correct 14 ms 1992 KB Output is correct
31 Correct 12 ms 1976 KB Output is correct
32 Correct 6 ms 1976 KB Output is correct
33 Correct 3 ms 1876 KB Output is correct
34 Correct 9 ms 1876 KB Output is correct
35 Correct 17 ms 1956 KB Output is correct
36 Correct 7 ms 1876 KB Output is correct
37 Correct 20 ms 1984 KB Output is correct
38 Correct 26 ms 1988 KB Output is correct
39 Correct 11 ms 1996 KB Output is correct
40 Correct 6 ms 1876 KB Output is correct
41 Correct 6 ms 1892 KB Output is correct
42 Correct 6 ms 1888 KB Output is correct
43 Correct 3 ms 1876 KB Output is correct
44 Correct 6 ms 1876 KB Output is correct
45 Correct 6 ms 1876 KB Output is correct
46 Correct 14 ms 1876 KB Output is correct
47 Correct 9 ms 1984 KB Output is correct
48 Correct 9 ms 1876 KB Output is correct
49 Correct 11 ms 1988 KB Output is correct
50 Correct 12 ms 2004 KB Output is correct
51 Correct 7 ms 1876 KB Output is correct
52 Correct 9 ms 1976 KB Output is correct
53 Correct 11 ms 1944 KB Output is correct
54 Correct 15 ms 1868 KB Output is correct
55 Correct 1675 ms 7944 KB Output is correct
56 Execution timed out 2056 ms 10356 KB Time limit exceeded
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 1872 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 1 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 1 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 1916 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 1880 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 1 ms 1876 KB Output is correct
29 Correct 17 ms 1952 KB Output is correct
30 Correct 14 ms 1992 KB Output is correct
31 Correct 12 ms 1976 KB Output is correct
32 Correct 6 ms 1976 KB Output is correct
33 Correct 3 ms 1876 KB Output is correct
34 Correct 9 ms 1876 KB Output is correct
35 Correct 17 ms 1956 KB Output is correct
36 Correct 7 ms 1876 KB Output is correct
37 Correct 20 ms 1984 KB Output is correct
38 Correct 26 ms 1988 KB Output is correct
39 Correct 11 ms 1996 KB Output is correct
40 Correct 6 ms 1876 KB Output is correct
41 Correct 6 ms 1892 KB Output is correct
42 Correct 6 ms 1888 KB Output is correct
43 Correct 3 ms 1876 KB Output is correct
44 Correct 6 ms 1876 KB Output is correct
45 Correct 6 ms 1876 KB Output is correct
46 Correct 14 ms 1876 KB Output is correct
47 Correct 9 ms 1984 KB Output is correct
48 Correct 9 ms 1876 KB Output is correct
49 Correct 11 ms 1988 KB Output is correct
50 Correct 12 ms 2004 KB Output is correct
51 Correct 7 ms 1876 KB Output is correct
52 Correct 9 ms 1976 KB Output is correct
53 Correct 11 ms 1944 KB Output is correct
54 Correct 15 ms 1868 KB Output is correct
55 Execution timed out 2078 ms 5608 KB Time limit exceeded
56 Halted 0 ms 0 KB -