답안 #989374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989374 2024-05-28T05:29:56 Z qwerasdfzxcl Joker (BOI20_joker) C++17
100 / 100
578 ms 24768 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct DSU{
	int path[400400], rank[400400];
	vector<array<int, 3>> st;

	void init(int n){
		st.clear();
		for (int i=1;i<=n;i++) path[i] = i, rank[i] = 0;
	}
	int find(int s){
		if (s==path[s]) return s;
		return find(path[s]);
	}
	void merge(int x, int y){
		x = find(x), y = find(y);
		if (x==y) {st.push_back({-1, -1, -1}); return;}
		if (rank[x] > rank[y]) swap(x, y);
		
		st.push_back({x, y, rank[y]});
		path[x] = y;
		if (rank[x]==rank[y]) rank[y]++;
	}
	void pop(int cnt){
		for (int i=1;i<=cnt;i++){
			auto [x, y, r] = st.back(); st.pop_back();
			if (x==-1) continue;
			path[x] = x;
			rank[y] = r;
		}
	}
}dsu;

int a[400400], b[400400], ans[400400], sz;

void rollback(int t){
	dsu.pop((sz-t) * 2);
	sz = t;
}

int push(int i){
	dsu.merge(a[i]*2, b[i]*2+1);
	dsu.merge(a[i]*2+1, b[i]*2);
	sz++;
	if (dsu.find(a[i]*2) == dsu.find(a[i]*2+1)) return 0;
	return 1;
}

void dnc(int l, int r, int s, int e){
	if (l > r) return;
	
	int m = (l+r)>>1;
	int t1 = sz;

	for (int i=min(r, s-1);i>=m;i--) push(i);
	int t2 = sz;

	for (int i=max(s, m);i<=e;i++){
		if (!push(i)) break;
		ans[m] = i;
	}

	rollback(t2);
	dnc(l, m-1, s, ans[m]);

	rollback(t1);
	for (int i=max(r+1, s);i<=ans[m]-1;i++) push(i);
	dnc(m+1, r, ans[m], e);

	rollback(t1);

}

int main(){
	int n, m, q;
	scanf("%d %d %d", &n, &m, &q);
	for (int i=1;i<=m;i++) scanf("%d %d", a+i, b+i);
	for (int i=1;i<=m;i++) a[i+m] = a[i], b[i+m] = b[i];

	dsu.init(n*2+3);
	dnc(1, m*2, 1, m*2);
	
	while(q--){
		int l, r;
		scanf("%d %d", &l, &r);

		int ll = r+1, rr = l-1 + m;

		if (ans[ll] >= rr) printf("NO\n");
		else printf("YES\n");
	}
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |  scanf("%d %d %d", &n, &m, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:80:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |  for (int i=1;i<=m;i++) scanf("%d %d", a+i, b+i);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~
Joker.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |   scanf("%d %d", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6612 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6584 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6488 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6612 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6584 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6488 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 4696 KB Output is correct
30 Correct 3 ms 6488 KB Output is correct
31 Correct 3 ms 2652 KB Output is correct
32 Correct 4 ms 2392 KB Output is correct
33 Correct 2 ms 2500 KB Output is correct
34 Correct 3 ms 2648 KB Output is correct
35 Correct 4 ms 6744 KB Output is correct
36 Correct 3 ms 4444 KB Output is correct
37 Correct 3 ms 2904 KB Output is correct
38 Correct 3 ms 4952 KB Output is correct
39 Correct 3 ms 6744 KB Output is correct
40 Correct 3 ms 6488 KB Output is correct
41 Correct 3 ms 6488 KB Output is correct
42 Correct 3 ms 6488 KB Output is correct
43 Correct 3 ms 6488 KB Output is correct
44 Correct 3 ms 6488 KB Output is correct
45 Correct 3 ms 6492 KB Output is correct
46 Correct 3 ms 6632 KB Output is correct
47 Correct 3 ms 6492 KB Output is correct
48 Correct 4 ms 6492 KB Output is correct
49 Correct 3 ms 4696 KB Output is correct
50 Correct 4 ms 6492 KB Output is correct
51 Correct 4 ms 6492 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 4 ms 6492 KB Output is correct
54 Correct 3 ms 6724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 374 ms 14476 KB Output is correct
4 Correct 422 ms 24768 KB Output is correct
5 Correct 373 ms 18452 KB Output is correct
6 Correct 320 ms 14356 KB Output is correct
7 Correct 327 ms 15512 KB Output is correct
8 Correct 532 ms 13716 KB Output is correct
9 Correct 578 ms 14272 KB Output is correct
10 Correct 525 ms 15000 KB Output is correct
11 Correct 375 ms 14520 KB Output is correct
12 Correct 395 ms 15580 KB Output is correct
13 Correct 522 ms 13760 KB Output is correct
14 Correct 527 ms 14524 KB Output is correct
15 Correct 486 ms 15040 KB Output is correct
16 Correct 500 ms 15552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6612 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6584 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6488 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 374 ms 14476 KB Output is correct
30 Correct 422 ms 24768 KB Output is correct
31 Correct 373 ms 18452 KB Output is correct
32 Correct 320 ms 14356 KB Output is correct
33 Correct 327 ms 15512 KB Output is correct
34 Correct 532 ms 13716 KB Output is correct
35 Correct 578 ms 14272 KB Output is correct
36 Correct 525 ms 15000 KB Output is correct
37 Correct 375 ms 14520 KB Output is correct
38 Correct 395 ms 15580 KB Output is correct
39 Correct 522 ms 13760 KB Output is correct
40 Correct 527 ms 14524 KB Output is correct
41 Correct 486 ms 15040 KB Output is correct
42 Correct 500 ms 15552 KB Output is correct
43 Correct 334 ms 15296 KB Output is correct
44 Correct 407 ms 24508 KB Output is correct
45 Correct 481 ms 18868 KB Output is correct
46 Correct 370 ms 15228 KB Output is correct
47 Correct 350 ms 15156 KB Output is correct
48 Correct 546 ms 14536 KB Output is correct
49 Correct 497 ms 15628 KB Output is correct
50 Correct 410 ms 14516 KB Output is correct
51 Correct 421 ms 15548 KB Output is correct
52 Correct 431 ms 16152 KB Output is correct
53 Correct 542 ms 14536 KB Output is correct
54 Correct 544 ms 14524 KB Output is correct
55 Correct 455 ms 15248 KB Output is correct
56 Correct 563 ms 15804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6612 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6584 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6488 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 4696 KB Output is correct
30 Correct 3 ms 6488 KB Output is correct
31 Correct 3 ms 2652 KB Output is correct
32 Correct 4 ms 2392 KB Output is correct
33 Correct 2 ms 2500 KB Output is correct
34 Correct 3 ms 2648 KB Output is correct
35 Correct 4 ms 6744 KB Output is correct
36 Correct 3 ms 4444 KB Output is correct
37 Correct 3 ms 2904 KB Output is correct
38 Correct 3 ms 4952 KB Output is correct
39 Correct 3 ms 6744 KB Output is correct
40 Correct 3 ms 6488 KB Output is correct
41 Correct 3 ms 6488 KB Output is correct
42 Correct 3 ms 6488 KB Output is correct
43 Correct 3 ms 6488 KB Output is correct
44 Correct 3 ms 6488 KB Output is correct
45 Correct 3 ms 6492 KB Output is correct
46 Correct 3 ms 6632 KB Output is correct
47 Correct 3 ms 6492 KB Output is correct
48 Correct 4 ms 6492 KB Output is correct
49 Correct 3 ms 4696 KB Output is correct
50 Correct 4 ms 6492 KB Output is correct
51 Correct 4 ms 6492 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 4 ms 6492 KB Output is correct
54 Correct 3 ms 6724 KB Output is correct
55 Correct 332 ms 11984 KB Output is correct
56 Correct 423 ms 21656 KB Output is correct
57 Correct 484 ms 16580 KB Output is correct
58 Correct 334 ms 12076 KB Output is correct
59 Correct 513 ms 12840 KB Output is correct
60 Correct 454 ms 14024 KB Output is correct
61 Correct 374 ms 14024 KB Output is correct
62 Correct 380 ms 14544 KB Output is correct
63 Correct 475 ms 13008 KB Output is correct
64 Correct 415 ms 14020 KB Output is correct
65 Correct 433 ms 14220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6612 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6584 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6488 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 4696 KB Output is correct
30 Correct 3 ms 6488 KB Output is correct
31 Correct 3 ms 2652 KB Output is correct
32 Correct 4 ms 2392 KB Output is correct
33 Correct 2 ms 2500 KB Output is correct
34 Correct 3 ms 2648 KB Output is correct
35 Correct 4 ms 6744 KB Output is correct
36 Correct 3 ms 4444 KB Output is correct
37 Correct 3 ms 2904 KB Output is correct
38 Correct 3 ms 4952 KB Output is correct
39 Correct 3 ms 6744 KB Output is correct
40 Correct 3 ms 6488 KB Output is correct
41 Correct 3 ms 6488 KB Output is correct
42 Correct 3 ms 6488 KB Output is correct
43 Correct 3 ms 6488 KB Output is correct
44 Correct 3 ms 6488 KB Output is correct
45 Correct 3 ms 6492 KB Output is correct
46 Correct 3 ms 6632 KB Output is correct
47 Correct 3 ms 6492 KB Output is correct
48 Correct 4 ms 6492 KB Output is correct
49 Correct 3 ms 4696 KB Output is correct
50 Correct 4 ms 6492 KB Output is correct
51 Correct 4 ms 6492 KB Output is correct
52 Correct 3 ms 6492 KB Output is correct
53 Correct 4 ms 6492 KB Output is correct
54 Correct 3 ms 6724 KB Output is correct
55 Correct 374 ms 14476 KB Output is correct
56 Correct 422 ms 24768 KB Output is correct
57 Correct 373 ms 18452 KB Output is correct
58 Correct 320 ms 14356 KB Output is correct
59 Correct 327 ms 15512 KB Output is correct
60 Correct 532 ms 13716 KB Output is correct
61 Correct 578 ms 14272 KB Output is correct
62 Correct 525 ms 15000 KB Output is correct
63 Correct 375 ms 14520 KB Output is correct
64 Correct 395 ms 15580 KB Output is correct
65 Correct 522 ms 13760 KB Output is correct
66 Correct 527 ms 14524 KB Output is correct
67 Correct 486 ms 15040 KB Output is correct
68 Correct 500 ms 15552 KB Output is correct
69 Correct 334 ms 15296 KB Output is correct
70 Correct 407 ms 24508 KB Output is correct
71 Correct 481 ms 18868 KB Output is correct
72 Correct 370 ms 15228 KB Output is correct
73 Correct 350 ms 15156 KB Output is correct
74 Correct 546 ms 14536 KB Output is correct
75 Correct 497 ms 15628 KB Output is correct
76 Correct 410 ms 14516 KB Output is correct
77 Correct 421 ms 15548 KB Output is correct
78 Correct 431 ms 16152 KB Output is correct
79 Correct 542 ms 14536 KB Output is correct
80 Correct 544 ms 14524 KB Output is correct
81 Correct 455 ms 15248 KB Output is correct
82 Correct 563 ms 15804 KB Output is correct
83 Correct 332 ms 11984 KB Output is correct
84 Correct 423 ms 21656 KB Output is correct
85 Correct 484 ms 16580 KB Output is correct
86 Correct 334 ms 12076 KB Output is correct
87 Correct 513 ms 12840 KB Output is correct
88 Correct 454 ms 14024 KB Output is correct
89 Correct 374 ms 14024 KB Output is correct
90 Correct 380 ms 14544 KB Output is correct
91 Correct 475 ms 13008 KB Output is correct
92 Correct 415 ms 14020 KB Output is correct
93 Correct 433 ms 14220 KB Output is correct
94 Correct 344 ms 15808 KB Output is correct
95 Correct 422 ms 18616 KB Output is correct
96 Correct 412 ms 19632 KB Output is correct
97 Correct 357 ms 15548 KB Output is correct
98 Correct 344 ms 15552 KB Output is correct
99 Correct 452 ms 15144 KB Output is correct
100 Correct 470 ms 16600 KB Output is correct
101 Correct 348 ms 15272 KB Output is correct
102 Correct 404 ms 16060 KB Output is correct
103 Correct 432 ms 17084 KB Output is correct
104 Correct 482 ms 15032 KB Output is correct
105 Correct 514 ms 16060 KB Output is correct
106 Correct 494 ms 17044 KB Output is correct
107 Correct 350 ms 18872 KB Output is correct
108 Correct 338 ms 15292 KB Output is correct
109 Correct 343 ms 15292 KB Output is correct
110 Correct 357 ms 15292 KB Output is correct
111 Correct 326 ms 15292 KB Output is correct
112 Correct 347 ms 15248 KB Output is correct
113 Correct 334 ms 15292 KB Output is correct
114 Correct 348 ms 15296 KB Output is correct
115 Correct 354 ms 15296 KB Output is correct
116 Correct 343 ms 15972 KB Output is correct