답안 #1080005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080005 2024-08-29T06:00:43 Z qwerasdfzxcl Joker (BOI20_joker) C++17
100 / 100
624 ms 22400 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 4 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 456 KB Output is correct
37 Correct 3 ms 604 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 3 ms 600 KB Output is correct
40 Correct 2 ms 608 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 3 ms 456 KB Output is correct
50 Correct 3 ms 508 KB Output is correct
51 Correct 3 ms 596 KB Output is correct
52 Correct 3 ms 604 KB Output is correct
53 Correct 3 ms 616 KB Output is correct
54 Correct 4 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 362 ms 13764 KB Output is correct
4 Correct 473 ms 21940 KB Output is correct
5 Correct 400 ms 17260 KB Output is correct
6 Correct 350 ms 13780 KB Output is correct
7 Correct 357 ms 13760 KB Output is correct
8 Correct 582 ms 12596 KB Output is correct
9 Correct 624 ms 13240 KB Output is correct
10 Correct 567 ms 15032 KB Output is correct
11 Correct 427 ms 13728 KB Output is correct
12 Correct 427 ms 15288 KB Output is correct
13 Correct 574 ms 12356 KB Output is correct
14 Correct 582 ms 13028 KB Output is correct
15 Correct 538 ms 14516 KB Output is correct
16 Correct 558 ms 15804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 362 ms 13764 KB Output is correct
30 Correct 473 ms 21940 KB Output is correct
31 Correct 400 ms 17260 KB Output is correct
32 Correct 350 ms 13780 KB Output is correct
33 Correct 357 ms 13760 KB Output is correct
34 Correct 582 ms 12596 KB Output is correct
35 Correct 624 ms 13240 KB Output is correct
36 Correct 567 ms 15032 KB Output is correct
37 Correct 427 ms 13728 KB Output is correct
38 Correct 427 ms 15288 KB Output is correct
39 Correct 574 ms 12356 KB Output is correct
40 Correct 582 ms 13028 KB Output is correct
41 Correct 538 ms 14516 KB Output is correct
42 Correct 558 ms 15804 KB Output is correct
43 Correct 379 ms 14036 KB Output is correct
44 Correct 480 ms 22400 KB Output is correct
45 Correct 534 ms 18052 KB Output is correct
46 Correct 403 ms 14008 KB Output is correct
47 Correct 410 ms 14044 KB Output is correct
48 Correct 598 ms 13772 KB Output is correct
49 Correct 607 ms 15572 KB Output is correct
50 Correct 454 ms 13608 KB Output is correct
51 Correct 441 ms 14676 KB Output is correct
52 Correct 476 ms 16036 KB Output is correct
53 Correct 555 ms 12476 KB Output is correct
54 Correct 599 ms 13748 KB Output is correct
55 Correct 524 ms 14776 KB Output is correct
56 Correct 580 ms 15828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 4 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 456 KB Output is correct
37 Correct 3 ms 604 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 3 ms 600 KB Output is correct
40 Correct 2 ms 608 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 3 ms 456 KB Output is correct
50 Correct 3 ms 508 KB Output is correct
51 Correct 3 ms 596 KB Output is correct
52 Correct 3 ms 604 KB Output is correct
53 Correct 3 ms 616 KB Output is correct
54 Correct 4 ms 600 KB Output is correct
55 Correct 333 ms 11492 KB Output is correct
56 Correct 447 ms 21644 KB Output is correct
57 Correct 449 ms 15044 KB Output is correct
58 Correct 321 ms 11452 KB Output is correct
59 Correct 530 ms 11444 KB Output is correct
60 Correct 510 ms 12476 KB Output is correct
61 Correct 385 ms 11452 KB Output is correct
62 Correct 421 ms 12988 KB Output is correct
63 Correct 524 ms 10500 KB Output is correct
64 Correct 492 ms 11964 KB Output is correct
65 Correct 482 ms 12776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 600 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 4 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 456 KB Output is correct
37 Correct 3 ms 604 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 3 ms 600 KB Output is correct
40 Correct 2 ms 608 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 604 KB Output is correct
43 Correct 3 ms 604 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 3 ms 456 KB Output is correct
50 Correct 3 ms 508 KB Output is correct
51 Correct 3 ms 596 KB Output is correct
52 Correct 3 ms 604 KB Output is correct
53 Correct 3 ms 616 KB Output is correct
54 Correct 4 ms 600 KB Output is correct
55 Correct 362 ms 13764 KB Output is correct
56 Correct 473 ms 21940 KB Output is correct
57 Correct 400 ms 17260 KB Output is correct
58 Correct 350 ms 13780 KB Output is correct
59 Correct 357 ms 13760 KB Output is correct
60 Correct 582 ms 12596 KB Output is correct
61 Correct 624 ms 13240 KB Output is correct
62 Correct 567 ms 15032 KB Output is correct
63 Correct 427 ms 13728 KB Output is correct
64 Correct 427 ms 15288 KB Output is correct
65 Correct 574 ms 12356 KB Output is correct
66 Correct 582 ms 13028 KB Output is correct
67 Correct 538 ms 14516 KB Output is correct
68 Correct 558 ms 15804 KB Output is correct
69 Correct 379 ms 14036 KB Output is correct
70 Correct 480 ms 22400 KB Output is correct
71 Correct 534 ms 18052 KB Output is correct
72 Correct 403 ms 14008 KB Output is correct
73 Correct 410 ms 14044 KB Output is correct
74 Correct 598 ms 13772 KB Output is correct
75 Correct 607 ms 15572 KB Output is correct
76 Correct 454 ms 13608 KB Output is correct
77 Correct 441 ms 14676 KB Output is correct
78 Correct 476 ms 16036 KB Output is correct
79 Correct 555 ms 12476 KB Output is correct
80 Correct 599 ms 13748 KB Output is correct
81 Correct 524 ms 14776 KB Output is correct
82 Correct 580 ms 15828 KB Output is correct
83 Correct 333 ms 11492 KB Output is correct
84 Correct 447 ms 21644 KB Output is correct
85 Correct 449 ms 15044 KB Output is correct
86 Correct 321 ms 11452 KB Output is correct
87 Correct 530 ms 11444 KB Output is correct
88 Correct 510 ms 12476 KB Output is correct
89 Correct 385 ms 11452 KB Output is correct
90 Correct 421 ms 12988 KB Output is correct
91 Correct 524 ms 10500 KB Output is correct
92 Correct 492 ms 11964 KB Output is correct
93 Correct 482 ms 12776 KB Output is correct
94 Correct 374 ms 14800 KB Output is correct
95 Correct 474 ms 18644 KB Output is correct
96 Correct 449 ms 17988 KB Output is correct
97 Correct 419 ms 14776 KB Output is correct
98 Correct 373 ms 14780 KB Output is correct
99 Correct 513 ms 14012 KB Output is correct
100 Correct 517 ms 16512 KB Output is correct
101 Correct 387 ms 14420 KB Output is correct
102 Correct 462 ms 15504 KB Output is correct
103 Correct 483 ms 16828 KB Output is correct
104 Correct 592 ms 13788 KB Output is correct
105 Correct 566 ms 15036 KB Output is correct
106 Correct 542 ms 16060 KB Output is correct
107 Correct 377 ms 18864 KB Output is correct
108 Correct 374 ms 14548 KB Output is correct
109 Correct 366 ms 14380 KB Output is correct
110 Correct 364 ms 14520 KB Output is correct
111 Correct 366 ms 14580 KB Output is correct
112 Correct 368 ms 14528 KB Output is correct
113 Correct 383 ms 14448 KB Output is correct
114 Correct 386 ms 14604 KB Output is correct
115 Correct 372 ms 14524 KB Output is correct
116 Correct 370 ms 14780 KB Output is correct