답안 #544754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544754 2022-04-02T16:28:08 Z rainboy Joker (BOI20_joker) C
100 / 100
617 ms 22700 KB
/* https://codeforces.com/blog/entry/80490?#comment-667089 (Benq) */
#include <stdio.h>
#include <string.h>

#define N	200000
#define M	200000
#define N_	(M * 2 + N)
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }

int ds[N * 2];

int find(int i) {
	return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}

void join(int i, int j) {
	i = find(i);
	j = find(j);
	if (i == j)
		return;
	if (ds[i] > ds[j])
		ds[i] = j;
	else {
		if (ds[i] == ds[j])
			ds[i]--;
		ds[j] = i;
	}
}

int tt[1 + N_][2], pp[1 + N_], mn[1 + N_], n, m; char odd[1 + N_], rev[1 + N_];

int dir(int u) {
	return tt[pp[u]][0] == u ? 0 : 1;
}

int is_root(int u) {
	return tt[pp[u]][0] != u && tt[pp[u]][1] != u;
}

void put(int u) {
	if (u) {
		int tmp;

		tmp = tt[u][0], tt[u][0] = tt[u][1], tt[u][1] = tmp;
		rev[u] ^= 1;
	}
}

void pus(int u) {
	if (rev[u])
		put(tt[u][0]), put(tt[u][1]), rev[u] = 0;
}

void pul(int u) {
	if (!rev[u]) {
		int l = tt[u][0], r = tt[u][1];

		mn[u] = min(u, min(mn[l], mn[r]));
		odd[u] = (u <= m * 2) ^ odd[l] ^ odd[r];
	}
}

void attach(int p, int u, int d) {
	if (p)
		tt[p][d] = u, pul(p);
	if (u)
		pp[u] = p;
}

void rotate(int u) {
	int v = pp[u], w = pp[v], du = dir(u), dv = dir(v);

	if (is_root(v))
		pp[u] = w;
	else
		attach(w, u, dv);
	attach(v, tt[u][du ^ 1], du);
	attach(u, v, du ^ 1);
}

void splay(int u) {
	while (!is_root(u)) {
		int v = pp[u], w = pp[v];

		pus(w), pus(v), pus(u);
		if (!is_root(v))
			rotate(dir(u) == dir(v) ? v : u);
		rotate(u);
	}
	pus(u);
}

int first(int u) {
	pus(u);
	while (tt[u][0])
		pus(u = tt[u][0]);
	splay(u);
	return u;
}

int find_min(int u) {
	pus(u);
	while (mn[u] != u)
		pus(u = tt[u][mn[tt[u][0]] == mn[u] ? 0 : 1]);
	splay(u);
	return u;
}

void expose(int u) {
	int v, w;

	for (w = 0, v = u; v; w = v, v = pp[v]) {
		splay(v);
		attach(v, w, 1);
	}
	splay(u);
}

void make_root(int u) {
	expose(u), put(u);
}

void link(int u, int v) {
	make_root(u), expose(v);
	attach(v, u, 1);
}

void cut(int u, int v) {
	make_root(u), expose(v);
	pp[tt[v][0]] = 0, attach(v, 0, 0);
}

int uu[1 + M * 2], vv[1 + M * 2]; char used[1 + M * 2];

void cut_(int h);

int cnt;

int link_(int h) {
	int u = uu[h], v = vv[h];

	make_root(u);
	expose(v);
	if (first(v) == u) {
		if (!odd[u])
			return 0;
		cut_(find_min(u));
	}
	link(u, h), link(v, h);
	used[h] = 1;
	return 1;
}

void cut_(int h) {
	if (used[h]) {
		int u = uu[h], v = vv[h];

		cut(u, h), cut(v, h);
		used[h] = 0;
	}
}

int main() {
	static int rr[1 + M];
	int q, h, l, r, u, v;

	scanf("%d%d%d", &n, &m, &q);
	for (h = 1; h <= m; h++) {
		scanf("%d%d", &u, &v);
		uu[h] = m * 2 + u, vv[h] = m * 2 + v;
		uu[m + h] = m * 2 + u, vv[m + h] = m * 2 + v;
	}
	memset(ds, -1, n * 2 * sizeof *ds);
	for (r = m; r > 0; r--) {
		u = uu[r] - m * 2 - 1, v = vv[r] - m * 2 - 1;
		if (find(u << 1 | 0) == find(v << 1 | 0))
			break;
		join(u << 1 | 0, v << 1 | 1), join(u << 1 | 1, v << 1 | 0);
	}
	if (r++ > 0) {
		mn[0] = INF;
		for (u = 1; u <= m * 2; u++)
			odd[u] = 1;
		for (h = r; h <= m; h++)
			link_(h);
		for (l = 1; l <= m; l++) {
			u = uu[l], v = vv[l];
			rr[l] = r - 1;
			while (r <= m + 1 && !link_(m + l)) {
				if (r == m + 1) {
					while (++l <= m)
						rr[l] = m + 1;
					break;
				}
				cut_(r++);
			}
		}
	}
	while (q--) {
		scanf("%d%d", &l, &r);
		printf(rr[l] <= r ? "NO\n" : "YES\n");
	}
	return 0;
}

Compilation message

Joker.c: In function 'main':
Joker.c:169:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  169 |  scanf("%d%d%d", &n, &m, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Joker.c:171:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  171 |   scanf("%d%d", &u, &v);
      |   ^~~~~~~~~~~~~~~~~~~~~
Joker.c:202:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  202 |   scanf("%d%d", &l, &r);
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 408 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 436 KB Output is correct
35 Correct 3 ms 500 KB Output is correct
36 Correct 3 ms 500 KB Output is correct
37 Correct 4 ms 436 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 3 ms 436 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 3 ms 468 KB Output is correct
43 Correct 4 ms 500 KB Output is correct
44 Correct 4 ms 468 KB Output is correct
45 Correct 3 ms 596 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 3 ms 468 KB Output is correct
48 Correct 3 ms 468 KB Output is correct
49 Correct 4 ms 520 KB Output is correct
50 Correct 3 ms 504 KB Output is correct
51 Correct 4 ms 432 KB Output is correct
52 Correct 3 ms 504 KB Output is correct
53 Correct 3 ms 488 KB Output is correct
54 Correct 4 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 218 ms 15340 KB Output is correct
4 Correct 104 ms 9144 KB Output is correct
5 Correct 256 ms 17612 KB Output is correct
6 Correct 203 ms 15372 KB Output is correct
7 Correct 238 ms 15436 KB Output is correct
8 Correct 480 ms 13764 KB Output is correct
9 Correct 374 ms 14856 KB Output is correct
10 Correct 238 ms 17616 KB Output is correct
11 Correct 216 ms 15256 KB Output is correct
12 Correct 192 ms 17512 KB Output is correct
13 Correct 558 ms 13208 KB Output is correct
14 Correct 475 ms 14284 KB Output is correct
15 Correct 302 ms 16456 KB Output is correct
16 Correct 236 ms 17980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 218 ms 15340 KB Output is correct
30 Correct 104 ms 9144 KB Output is correct
31 Correct 256 ms 17612 KB Output is correct
32 Correct 203 ms 15372 KB Output is correct
33 Correct 238 ms 15436 KB Output is correct
34 Correct 480 ms 13764 KB Output is correct
35 Correct 374 ms 14856 KB Output is correct
36 Correct 238 ms 17616 KB Output is correct
37 Correct 216 ms 15256 KB Output is correct
38 Correct 192 ms 17512 KB Output is correct
39 Correct 558 ms 13208 KB Output is correct
40 Correct 475 ms 14284 KB Output is correct
41 Correct 302 ms 16456 KB Output is correct
42 Correct 236 ms 17980 KB Output is correct
43 Correct 203 ms 15684 KB Output is correct
44 Correct 98 ms 9592 KB Output is correct
45 Correct 333 ms 21324 KB Output is correct
46 Correct 205 ms 15660 KB Output is correct
47 Correct 239 ms 15656 KB Output is correct
48 Correct 377 ms 15340 KB Output is correct
49 Correct 248 ms 18092 KB Output is correct
50 Correct 232 ms 14996 KB Output is correct
51 Correct 210 ms 16860 KB Output is correct
52 Correct 201 ms 18280 KB Output is correct
53 Correct 566 ms 13436 KB Output is correct
54 Correct 503 ms 15072 KB Output is correct
55 Correct 339 ms 16716 KB Output is correct
56 Correct 270 ms 18356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 408 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 436 KB Output is correct
35 Correct 3 ms 500 KB Output is correct
36 Correct 3 ms 500 KB Output is correct
37 Correct 4 ms 436 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 3 ms 436 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 3 ms 468 KB Output is correct
43 Correct 4 ms 500 KB Output is correct
44 Correct 4 ms 468 KB Output is correct
45 Correct 3 ms 596 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 3 ms 468 KB Output is correct
48 Correct 3 ms 468 KB Output is correct
49 Correct 4 ms 520 KB Output is correct
50 Correct 3 ms 504 KB Output is correct
51 Correct 4 ms 432 KB Output is correct
52 Correct 3 ms 504 KB Output is correct
53 Correct 3 ms 488 KB Output is correct
54 Correct 4 ms 528 KB Output is correct
55 Correct 192 ms 13148 KB Output is correct
56 Correct 57 ms 7464 KB Output is correct
57 Correct 133 ms 15212 KB Output is correct
58 Correct 205 ms 13048 KB Output is correct
59 Correct 447 ms 12940 KB Output is correct
60 Correct 319 ms 14636 KB Output is correct
61 Correct 209 ms 13156 KB Output is correct
62 Correct 222 ms 15168 KB Output is correct
63 Correct 605 ms 11412 KB Output is correct
64 Correct 360 ms 13576 KB Output is correct
65 Correct 257 ms 15276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 296 KB Output is correct
23 Correct 1 ms 292 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 408 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 436 KB Output is correct
35 Correct 3 ms 500 KB Output is correct
36 Correct 3 ms 500 KB Output is correct
37 Correct 4 ms 436 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 3 ms 468 KB Output is correct
40 Correct 3 ms 436 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 3 ms 468 KB Output is correct
43 Correct 4 ms 500 KB Output is correct
44 Correct 4 ms 468 KB Output is correct
45 Correct 3 ms 596 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 3 ms 468 KB Output is correct
48 Correct 3 ms 468 KB Output is correct
49 Correct 4 ms 520 KB Output is correct
50 Correct 3 ms 504 KB Output is correct
51 Correct 4 ms 432 KB Output is correct
52 Correct 3 ms 504 KB Output is correct
53 Correct 3 ms 488 KB Output is correct
54 Correct 4 ms 528 KB Output is correct
55 Correct 218 ms 15340 KB Output is correct
56 Correct 104 ms 9144 KB Output is correct
57 Correct 256 ms 17612 KB Output is correct
58 Correct 203 ms 15372 KB Output is correct
59 Correct 238 ms 15436 KB Output is correct
60 Correct 480 ms 13764 KB Output is correct
61 Correct 374 ms 14856 KB Output is correct
62 Correct 238 ms 17616 KB Output is correct
63 Correct 216 ms 15256 KB Output is correct
64 Correct 192 ms 17512 KB Output is correct
65 Correct 558 ms 13208 KB Output is correct
66 Correct 475 ms 14284 KB Output is correct
67 Correct 302 ms 16456 KB Output is correct
68 Correct 236 ms 17980 KB Output is correct
69 Correct 203 ms 15684 KB Output is correct
70 Correct 98 ms 9592 KB Output is correct
71 Correct 333 ms 21324 KB Output is correct
72 Correct 205 ms 15660 KB Output is correct
73 Correct 239 ms 15656 KB Output is correct
74 Correct 377 ms 15340 KB Output is correct
75 Correct 248 ms 18092 KB Output is correct
76 Correct 232 ms 14996 KB Output is correct
77 Correct 210 ms 16860 KB Output is correct
78 Correct 201 ms 18280 KB Output is correct
79 Correct 566 ms 13436 KB Output is correct
80 Correct 503 ms 15072 KB Output is correct
81 Correct 339 ms 16716 KB Output is correct
82 Correct 270 ms 18356 KB Output is correct
83 Correct 192 ms 13148 KB Output is correct
84 Correct 57 ms 7464 KB Output is correct
85 Correct 133 ms 15212 KB Output is correct
86 Correct 205 ms 13048 KB Output is correct
87 Correct 447 ms 12940 KB Output is correct
88 Correct 319 ms 14636 KB Output is correct
89 Correct 209 ms 13156 KB Output is correct
90 Correct 222 ms 15168 KB Output is correct
91 Correct 605 ms 11412 KB Output is correct
92 Correct 360 ms 13576 KB Output is correct
93 Correct 257 ms 15276 KB Output is correct
94 Correct 247 ms 16368 KB Output is correct
95 Correct 329 ms 20656 KB Output is correct
96 Correct 248 ms 18528 KB Output is correct
97 Correct 281 ms 16352 KB Output is correct
98 Correct 292 ms 16332 KB Output is correct
99 Correct 573 ms 15304 KB Output is correct
100 Correct 259 ms 19228 KB Output is correct
101 Correct 266 ms 15828 KB Output is correct
102 Correct 263 ms 17484 KB Output is correct
103 Correct 275 ms 19056 KB Output is correct
104 Correct 617 ms 14680 KB Output is correct
105 Correct 376 ms 16880 KB Output is correct
106 Correct 281 ms 18504 KB Output is correct
107 Correct 229 ms 22700 KB Output is correct
108 Correct 233 ms 16140 KB Output is correct
109 Correct 225 ms 16084 KB Output is correct
110 Correct 213 ms 16040 KB Output is correct
111 Correct 212 ms 16072 KB Output is correct
112 Correct 223 ms 16156 KB Output is correct
113 Correct 202 ms 16136 KB Output is correct
114 Correct 212 ms 16232 KB Output is correct
115 Correct 209 ms 16084 KB Output is correct
116 Correct 218 ms 16048 KB Output is correct