답안 #441231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441231 2021-07-04T17:37:51 Z ritul_kr_singh Joker (BOI20_joker) C++17
100 / 100
1665 ms 237476 KB
#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 0 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 0 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 332 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 468 KB Output is correct
37 Correct 14 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 3 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 4 ms 460 KB Output is correct
45 Correct 5 ms 476 KB Output is correct
46 Correct 8 ms 460 KB Output is correct
47 Correct 4 ms 460 KB Output is correct
48 Correct 5 ms 460 KB Output is correct
49 Correct 4 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 5 ms 492 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 1054 ms 123356 KB Output is correct
4 Correct 252 ms 236484 KB Output is correct
5 Correct 278 ms 215560 KB Output is correct
6 Correct 195 ms 123204 KB Output is correct
7 Correct 206 ms 123252 KB Output is correct
8 Correct 298 ms 77100 KB Output is correct
9 Correct 367 ms 123356 KB Output is correct
10 Correct 803 ms 237416 KB Output is correct
11 Correct 447 ms 123332 KB Output is correct
12 Correct 718 ms 215872 KB Output is correct
13 Correct 200 ms 30656 KB Output is correct
14 Correct 299 ms 76996 KB Output is correct
15 Correct 668 ms 169616 KB Output is correct
16 Correct 794 ms 237240 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 0 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 1054 ms 123356 KB Output is correct
30 Correct 252 ms 236484 KB Output is correct
31 Correct 278 ms 215560 KB Output is correct
32 Correct 195 ms 123204 KB Output is correct
33 Correct 206 ms 123252 KB Output is correct
34 Correct 298 ms 77100 KB Output is correct
35 Correct 367 ms 123356 KB Output is correct
36 Correct 803 ms 237416 KB Output is correct
37 Correct 447 ms 123332 KB Output is correct
38 Correct 718 ms 215872 KB Output is correct
39 Correct 200 ms 30656 KB Output is correct
40 Correct 299 ms 76996 KB Output is correct
41 Correct 668 ms 169616 KB Output is correct
42 Correct 794 ms 237240 KB Output is correct
43 Correct 1049 ms 123196 KB Output is correct
44 Correct 241 ms 236460 KB Output is correct
45 Correct 591 ms 237416 KB Output is correct
46 Correct 196 ms 123204 KB Output is correct
47 Correct 226 ms 123208 KB Output is correct
48 Correct 449 ms 123332 KB Output is correct
49 Correct 828 ms 237476 KB Output is correct
50 Correct 402 ms 100164 KB Output is correct
51 Correct 578 ms 169464 KB Output is correct
52 Correct 769 ms 237152 KB Output is correct
53 Correct 196 ms 30660 KB Output is correct
54 Correct 444 ms 100084 KB Output is correct
55 Correct 644 ms 169556 KB Output is correct
56 Correct 836 ms 237136 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 0 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 332 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 468 KB Output is correct
37 Correct 14 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 3 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 4 ms 460 KB Output is correct
45 Correct 5 ms 476 KB Output is correct
46 Correct 8 ms 460 KB Output is correct
47 Correct 4 ms 460 KB Output is correct
48 Correct 5 ms 460 KB Output is correct
49 Correct 4 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 5 ms 492 KB Output is correct
55 Correct 305 ms 120840 KB Output is correct
56 Correct 194 ms 234436 KB Output is correct
57 Correct 185 ms 213156 KB Output is correct
58 Correct 129 ms 120936 KB Output is correct
59 Correct 204 ms 121024 KB Output is correct
60 Correct 372 ms 190660 KB Output is correct
61 Correct 225 ms 120804 KB Output is correct
62 Correct 398 ms 213620 KB Output is correct
63 Correct 102 ms 51400 KB Output is correct
64 Correct 253 ms 144028 KB Output is correct
65 Correct 411 ms 213572 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 0 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 332 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 468 KB Output is correct
37 Correct 14 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 3 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 4 ms 460 KB Output is correct
45 Correct 5 ms 476 KB Output is correct
46 Correct 8 ms 460 KB Output is correct
47 Correct 4 ms 460 KB Output is correct
48 Correct 5 ms 460 KB Output is correct
49 Correct 4 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 5 ms 492 KB Output is correct
55 Correct 1054 ms 123356 KB Output is correct
56 Correct 252 ms 236484 KB Output is correct
57 Correct 278 ms 215560 KB Output is correct
58 Correct 195 ms 123204 KB Output is correct
59 Correct 206 ms 123252 KB Output is correct
60 Correct 298 ms 77100 KB Output is correct
61 Correct 367 ms 123356 KB Output is correct
62 Correct 803 ms 237416 KB Output is correct
63 Correct 447 ms 123332 KB Output is correct
64 Correct 718 ms 215872 KB Output is correct
65 Correct 200 ms 30656 KB Output is correct
66 Correct 299 ms 76996 KB Output is correct
67 Correct 668 ms 169616 KB Output is correct
68 Correct 794 ms 237240 KB Output is correct
69 Correct 1049 ms 123196 KB Output is correct
70 Correct 241 ms 236460 KB Output is correct
71 Correct 591 ms 237416 KB Output is correct
72 Correct 196 ms 123204 KB Output is correct
73 Correct 226 ms 123208 KB Output is correct
74 Correct 449 ms 123332 KB Output is correct
75 Correct 828 ms 237476 KB Output is correct
76 Correct 402 ms 100164 KB Output is correct
77 Correct 578 ms 169464 KB Output is correct
78 Correct 769 ms 237152 KB Output is correct
79 Correct 196 ms 30660 KB Output is correct
80 Correct 444 ms 100084 KB Output is correct
81 Correct 644 ms 169556 KB Output is correct
82 Correct 836 ms 237136 KB Output is correct
83 Correct 305 ms 120840 KB Output is correct
84 Correct 194 ms 234436 KB Output is correct
85 Correct 185 ms 213156 KB Output is correct
86 Correct 129 ms 120936 KB Output is correct
87 Correct 204 ms 121024 KB Output is correct
88 Correct 372 ms 190660 KB Output is correct
89 Correct 225 ms 120804 KB Output is correct
90 Correct 398 ms 213620 KB Output is correct
91 Correct 102 ms 51400 KB Output is correct
92 Correct 253 ms 144028 KB Output is correct
93 Correct 411 ms 213572 KB Output is correct
94 Correct 856 ms 123420 KB Output is correct
95 Correct 1665 ms 237188 KB Output is correct
96 Correct 400 ms 215564 KB Output is correct
97 Correct 209 ms 123424 KB Output is correct
98 Correct 242 ms 123352 KB Output is correct
99 Correct 745 ms 77228 KB Output is correct
100 Correct 1138 ms 237388 KB Output is correct
101 Correct 540 ms 100480 KB Output is correct
102 Correct 778 ms 169620 KB Output is correct
103 Correct 1012 ms 237236 KB Output is correct
104 Correct 412 ms 53904 KB Output is correct
105 Correct 799 ms 146540 KB Output is correct
106 Correct 1031 ms 215996 KB Output is correct
107 Correct 255 ms 235768 KB Output is correct
108 Correct 1397 ms 122968 KB Output is correct
109 Correct 1453 ms 122880 KB Output is correct
110 Correct 1458 ms 122912 KB Output is correct
111 Correct 1459 ms 123020 KB Output is correct
112 Correct 1470 ms 122776 KB Output is correct
113 Correct 1486 ms 122840 KB Output is correct
114 Correct 1466 ms 122980 KB Output is correct
115 Correct 1463 ms 122924 KB Output is correct
116 Correct 1464 ms 122904 KB Output is correct