답안 #441230

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441230 2021-07-04T17:36:23 Z ritul_kr_singh Joker (BOI20_joker) C++17
100 / 100
1611 ms 242392 KB
#pragma GCC optimize("Ofast,unroll-loops")
 
#include <bits/stdc++.h>
using namespace std;
// #define int long long
 
const int MAXN = 2e5, B = 850, NUM = MAXN / B + 2;
 
int a[NUM][MAXN];
bool p[NUM][MAXN], b[NUM];
int rollback[4][B+1];
int n, m, q, x[MAXN], y[MAXN], ans[MAXN+1], rP = 0, r, c = 1, L[MAXN], R[MAXN], cnt[MAXN+1];
int last[NUM];
 
void unite(int i){
	bool pS = 0, pT = 0;
	int u = x[i], v = y[i];
	while(a[r][u] >= 0) pS ^= p[r][u], u = a[r][u];
	while(a[r][v] >= 0) pT ^= p[r][v], v = a[r][v];
	if(u == v){
		b[r] = b[r] || (pS == pT);
		return;
	}
	if(a[r][u] > a[r][v]) swap(u, v);
	if(!c){
		rollback[0][rP] = u;
		rollback[1][rP] = v;
		rollback[2][rP] = a[r][v];
		rollback[3][rP] = p[r][v];
		++rP;
	}
	a[r][u] += a[r][v];
	a[r][v] = u;
	p[r][v] = pS ^ pT ^ 1;
}
 
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m >> q;
	for(int i=0; i<m; ++i){
		cin >> x[i] >> y[i], --x[i], --y[i];
 
		if(i % B) continue;
		r = i / B;
 
		if(i){
			b[r] = b[r-1];
			for(int j=0; j<n; ++j) a[r][j] = a[r-1][j];
			for(int j=0; j<n; ++j) p[r][j] = p[r-1][j];
			for(int j=i-B; j<i; ++j) unite(j);
		}else fill(a[r], a[r]+n, -1);
	}
	fill(last, last+NUM, m);
	for(int i=0; i<q; ++i){
		cin >> L[i] >> R[i];
		++cnt[R[i]];
	}
 
	int z = ++r;
	b[r] = b[r-1];
	for(int j=0; j<n; ++j) a[r][j] = a[r-1][j];
	for(int j=0; j<n; ++j) p[r][j] = p[r-1][j];
	for(int j=(r-1)*B; j<m; ++j) unite(j);
	if(!b[r]){
		while(q--) cout << "NO\n";
		return 0;
	}
 
	for(int i=m; i; --i){
		if(cnt[i] || i==m){
			c = 1;
			while(z && b[z-1]){
				--z;
				r = z-1;
				while(last[r] > i) unite(--last[r]);
			}
			if(!z) break;
	 
			r = z - 1, c = 0;
			int l = r*B;
			while(!b[r]) unite(l++);
			b[r] = 0, ans[i] = l;
	 
			while(rP){
				--rP;
				a[r][rollback[1][rP]] = rollback[2][rP];
				a[r][rollback[0][rP]] -= rollback[2][rP];
				p[r][rollback[1][rP]] = rollback[3][rP];
			}
		}
		c = 1, r = z-1;
		unite(i-1);
		--last[r];
	}
	for(int i=0; i<q; ++i){
		cout << (ans[R[i]] >= L[i] ? "NO" : "YES") << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 4 ms 460 KB Output is correct
31 Correct 6 ms 460 KB Output is correct
32 Correct 4 ms 460 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 6 ms 460 KB Output is correct
35 Correct 6 ms 460 KB Output is correct
36 Correct 6 ms 464 KB Output is correct
37 Correct 14 ms 496 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 2 ms 460 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 5 ms 460 KB Output is correct
45 Correct 5 ms 460 KB Output is correct
46 Correct 8 ms 500 KB Output is correct
47 Correct 3 ms 460 KB Output is correct
48 Correct 5 ms 460 KB Output is correct
49 Correct 5 ms 460 KB Output is correct
50 Correct 5 ms 460 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 4 ms 460 KB Output is correct
53 Correct 5 ms 460 KB Output is correct
54 Correct 6 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1045 ms 123284 KB Output is correct
4 Correct 210 ms 236472 KB Output is correct
5 Correct 246 ms 215568 KB Output is correct
6 Correct 172 ms 123204 KB Output is correct
7 Correct 190 ms 123284 KB Output is correct
8 Correct 290 ms 77124 KB Output is correct
9 Correct 355 ms 123360 KB Output is correct
10 Correct 775 ms 237212 KB Output is correct
11 Correct 436 ms 123204 KB Output is correct
12 Correct 701 ms 215916 KB Output is correct
13 Correct 199 ms 30788 KB Output is correct
14 Correct 300 ms 76988 KB Output is correct
15 Correct 650 ms 169544 KB Output is correct
16 Correct 767 ms 237036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1045 ms 123284 KB Output is correct
30 Correct 210 ms 236472 KB Output is correct
31 Correct 246 ms 215568 KB Output is correct
32 Correct 172 ms 123204 KB Output is correct
33 Correct 190 ms 123284 KB Output is correct
34 Correct 290 ms 77124 KB Output is correct
35 Correct 355 ms 123360 KB Output is correct
36 Correct 775 ms 237212 KB Output is correct
37 Correct 436 ms 123204 KB Output is correct
38 Correct 701 ms 215916 KB Output is correct
39 Correct 199 ms 30788 KB Output is correct
40 Correct 300 ms 76988 KB Output is correct
41 Correct 650 ms 169544 KB Output is correct
42 Correct 767 ms 237036 KB Output is correct
43 Correct 1044 ms 123384 KB Output is correct
44 Correct 198 ms 236484 KB Output is correct
45 Correct 565 ms 237480 KB Output is correct
46 Correct 177 ms 123204 KB Output is correct
47 Correct 182 ms 123192 KB Output is correct
48 Correct 439 ms 123440 KB Output is correct
49 Correct 788 ms 237268 KB Output is correct
50 Correct 403 ms 100220 KB Output is correct
51 Correct 557 ms 169540 KB Output is correct
52 Correct 710 ms 237172 KB Output is correct
53 Correct 191 ms 30660 KB Output is correct
54 Correct 426 ms 100176 KB Output is correct
55 Correct 597 ms 169756 KB Output is correct
56 Correct 786 ms 237236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 4 ms 460 KB Output is correct
31 Correct 6 ms 460 KB Output is correct
32 Correct 4 ms 460 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 6 ms 460 KB Output is correct
35 Correct 6 ms 460 KB Output is correct
36 Correct 6 ms 464 KB Output is correct
37 Correct 14 ms 496 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 2 ms 460 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 5 ms 460 KB Output is correct
45 Correct 5 ms 460 KB Output is correct
46 Correct 8 ms 500 KB Output is correct
47 Correct 3 ms 460 KB Output is correct
48 Correct 5 ms 460 KB Output is correct
49 Correct 5 ms 460 KB Output is correct
50 Correct 5 ms 460 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 4 ms 460 KB Output is correct
53 Correct 5 ms 460 KB Output is correct
54 Correct 6 ms 496 KB Output is correct
55 Correct 283 ms 120832 KB Output is correct
56 Correct 154 ms 234376 KB Output is correct
57 Correct 151 ms 213184 KB Output is correct
58 Correct 110 ms 120828 KB Output is correct
59 Correct 204 ms 121072 KB Output is correct
60 Correct 340 ms 190692 KB Output is correct
61 Correct 208 ms 120876 KB Output is correct
62 Correct 366 ms 213444 KB Output is correct
63 Correct 94 ms 51500 KB Output is correct
64 Correct 230 ms 144060 KB Output is correct
65 Correct 376 ms 213392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 4 ms 460 KB Output is correct
31 Correct 6 ms 460 KB Output is correct
32 Correct 4 ms 460 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 6 ms 460 KB Output is correct
35 Correct 6 ms 460 KB Output is correct
36 Correct 6 ms 464 KB Output is correct
37 Correct 14 ms 496 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 2 ms 460 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 3 ms 460 KB Output is correct
44 Correct 5 ms 460 KB Output is correct
45 Correct 5 ms 460 KB Output is correct
46 Correct 8 ms 500 KB Output is correct
47 Correct 3 ms 460 KB Output is correct
48 Correct 5 ms 460 KB Output is correct
49 Correct 5 ms 460 KB Output is correct
50 Correct 5 ms 460 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 4 ms 460 KB Output is correct
53 Correct 5 ms 460 KB Output is correct
54 Correct 6 ms 496 KB Output is correct
55 Correct 1045 ms 123284 KB Output is correct
56 Correct 210 ms 236472 KB Output is correct
57 Correct 246 ms 215568 KB Output is correct
58 Correct 172 ms 123204 KB Output is correct
59 Correct 190 ms 123284 KB Output is correct
60 Correct 290 ms 77124 KB Output is correct
61 Correct 355 ms 123360 KB Output is correct
62 Correct 775 ms 237212 KB Output is correct
63 Correct 436 ms 123204 KB Output is correct
64 Correct 701 ms 215916 KB Output is correct
65 Correct 199 ms 30788 KB Output is correct
66 Correct 300 ms 76988 KB Output is correct
67 Correct 650 ms 169544 KB Output is correct
68 Correct 767 ms 237036 KB Output is correct
69 Correct 1044 ms 123384 KB Output is correct
70 Correct 198 ms 236484 KB Output is correct
71 Correct 565 ms 237480 KB Output is correct
72 Correct 177 ms 123204 KB Output is correct
73 Correct 182 ms 123192 KB Output is correct
74 Correct 439 ms 123440 KB Output is correct
75 Correct 788 ms 237268 KB Output is correct
76 Correct 403 ms 100220 KB Output is correct
77 Correct 557 ms 169540 KB Output is correct
78 Correct 710 ms 237172 KB Output is correct
79 Correct 191 ms 30660 KB Output is correct
80 Correct 426 ms 100176 KB Output is correct
81 Correct 597 ms 169756 KB Output is correct
82 Correct 786 ms 237236 KB Output is correct
83 Correct 283 ms 120832 KB Output is correct
84 Correct 154 ms 234376 KB Output is correct
85 Correct 151 ms 213184 KB Output is correct
86 Correct 110 ms 120828 KB Output is correct
87 Correct 204 ms 121072 KB Output is correct
88 Correct 340 ms 190692 KB Output is correct
89 Correct 208 ms 120876 KB Output is correct
90 Correct 366 ms 213444 KB Output is correct
91 Correct 94 ms 51500 KB Output is correct
92 Correct 230 ms 144060 KB Output is correct
93 Correct 376 ms 213392 KB Output is correct
94 Correct 843 ms 123276 KB Output is correct
95 Correct 1611 ms 237040 KB Output is correct
96 Correct 376 ms 220592 KB Output is correct
97 Correct 190 ms 128260 KB Output is correct
98 Correct 229 ms 128324 KB Output is correct
99 Correct 762 ms 81996 KB Output is correct
100 Correct 1133 ms 242392 KB Output is correct
101 Correct 535 ms 105264 KB Output is correct
102 Correct 761 ms 174652 KB Output is correct
103 Correct 1018 ms 242380 KB Output is correct
104 Correct 423 ms 58776 KB Output is correct
105 Correct 815 ms 151464 KB Output is correct
106 Correct 1010 ms 221072 KB Output is correct
107 Correct 210 ms 241092 KB Output is correct
108 Correct 1397 ms 127684 KB Output is correct
109 Correct 1441 ms 127760 KB Output is correct
110 Correct 1459 ms 127800 KB Output is correct
111 Correct 1445 ms 127648 KB Output is correct
112 Correct 1445 ms 127604 KB Output is correct
113 Correct 1457 ms 127752 KB Output is correct
114 Correct 1455 ms 127884 KB Output is correct
115 Correct 1465 ms 127680 KB Output is correct
116 Correct 1463 ms 127924 KB Output is correct