답안 #441224

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441224 2021-07-04T17:23:53 Z ritul_kr_singh Joker (BOI20_joker) C++17
71 / 100
2000 ms 242336 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];
 
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;

		fill(a[r], a[r]+n, -1);
 
		if(i+B >= m){
			for(int j=0; j<i; ++j) unite(j);
		}
	}
	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; z && i; --i){
		if(cnt[i]){
			c=1;
			while(z && b[z-1]){
				--z;
				if(!z) break;
				r = z-1;
				int s = r*B;
				for(int j=0; j<s; ++j) unite(j);
				for(int j=i; j<m; ++j) unite(j);
			}
			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);
	}
	for(int i=0; i<q; ++i){
		cout << (ans[R[i]] >= L[i] ? "NO" : "YES") << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 320 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 320 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 324 KB Output is correct
14 Correct 1 ms 324 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 324 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 320 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 0 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 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 320 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 320 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 324 KB Output is correct
14 Correct 1 ms 324 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 324 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 320 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 524 KB Output is correct
32 Correct 4 ms 588 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 7 ms 460 KB Output is correct
37 Correct 14 ms 524 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 3 ms 464 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 460 KB Output is correct
46 Correct 8 ms 464 KB Output is correct
47 Correct 4 ms 464 KB Output is correct
48 Correct 5 ms 416 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 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1457 ms 127352 KB Output is correct
4 Correct 177 ms 194244 KB Output is correct
5 Correct 848 ms 220144 KB Output is correct
6 Correct 827 ms 127376 KB Output is correct
7 Correct 900 ms 127328 KB Output is correct
8 Correct 1157 ms 80580 KB Output is correct
9 Correct 1196 ms 126744 KB Output is correct
10 Correct 1575 ms 240808 KB Output is correct
11 Correct 1049 ms 127344 KB Output is correct
12 Correct 1334 ms 219940 KB Output is correct
13 Correct 1000 ms 34732 KB Output is correct
14 Correct 1149 ms 81052 KB Output is correct
15 Correct 1596 ms 173572 KB Output is correct
16 Correct 1590 ms 241224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 320 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 320 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 324 KB Output is correct
14 Correct 1 ms 324 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 324 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 320 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 1457 ms 127352 KB Output is correct
30 Correct 177 ms 194244 KB Output is correct
31 Correct 848 ms 220144 KB Output is correct
32 Correct 827 ms 127376 KB Output is correct
33 Correct 900 ms 127328 KB Output is correct
34 Correct 1157 ms 80580 KB Output is correct
35 Correct 1196 ms 126744 KB Output is correct
36 Correct 1575 ms 240808 KB Output is correct
37 Correct 1049 ms 127344 KB Output is correct
38 Correct 1334 ms 219940 KB Output is correct
39 Correct 1000 ms 34732 KB Output is correct
40 Correct 1149 ms 81052 KB Output is correct
41 Correct 1596 ms 173572 KB Output is correct
42 Correct 1590 ms 241224 KB Output is correct
43 Correct 1464 ms 127656 KB Output is correct
44 Correct 179 ms 194756 KB Output is correct
45 Correct 1094 ms 241972 KB Output is correct
46 Correct 875 ms 127584 KB Output is correct
47 Correct 896 ms 127680 KB Output is correct
48 Correct 1304 ms 127432 KB Output is correct
49 Correct 1590 ms 241252 KB Output is correct
50 Correct 978 ms 104484 KB Output is correct
51 Correct 1241 ms 174076 KB Output is correct
52 Correct 1401 ms 241544 KB Output is correct
53 Correct 1010 ms 35044 KB Output is correct
54 Correct 1316 ms 104616 KB Output is correct
55 Correct 1484 ms 174104 KB Output is correct
56 Correct 1607 ms 241500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 320 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 320 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 324 KB Output is correct
14 Correct 1 ms 324 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 324 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 320 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 524 KB Output is correct
32 Correct 4 ms 588 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 7 ms 460 KB Output is correct
37 Correct 14 ms 524 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 3 ms 464 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 460 KB Output is correct
46 Correct 8 ms 464 KB Output is correct
47 Correct 4 ms 464 KB Output is correct
48 Correct 5 ms 416 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 460 KB Output is correct
55 Correct 707 ms 123352 KB Output is correct
56 Correct 134 ms 191144 KB Output is correct
57 Correct 766 ms 215688 KB Output is correct
58 Correct 802 ms 123396 KB Output is correct
59 Correct 1092 ms 123412 KB Output is correct
60 Correct 1188 ms 193144 KB Output is correct
61 Correct 852 ms 123284 KB Output is correct
62 Correct 1022 ms 216212 KB Output is correct
63 Correct 900 ms 53636 KB Output is correct
64 Correct 1156 ms 146536 KB Output is correct
65 Correct 1219 ms 216096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 320 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 320 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 320 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 324 KB Output is correct
14 Correct 1 ms 324 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 324 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 320 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 524 KB Output is correct
32 Correct 4 ms 588 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 7 ms 460 KB Output is correct
37 Correct 14 ms 524 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 3 ms 464 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 460 KB Output is correct
46 Correct 8 ms 464 KB Output is correct
47 Correct 4 ms 464 KB Output is correct
48 Correct 5 ms 416 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 460 KB Output is correct
55 Correct 1457 ms 127352 KB Output is correct
56 Correct 177 ms 194244 KB Output is correct
57 Correct 848 ms 220144 KB Output is correct
58 Correct 827 ms 127376 KB Output is correct
59 Correct 900 ms 127328 KB Output is correct
60 Correct 1157 ms 80580 KB Output is correct
61 Correct 1196 ms 126744 KB Output is correct
62 Correct 1575 ms 240808 KB Output is correct
63 Correct 1049 ms 127344 KB Output is correct
64 Correct 1334 ms 219940 KB Output is correct
65 Correct 1000 ms 34732 KB Output is correct
66 Correct 1149 ms 81052 KB Output is correct
67 Correct 1596 ms 173572 KB Output is correct
68 Correct 1590 ms 241224 KB Output is correct
69 Correct 1464 ms 127656 KB Output is correct
70 Correct 179 ms 194756 KB Output is correct
71 Correct 1094 ms 241972 KB Output is correct
72 Correct 875 ms 127584 KB Output is correct
73 Correct 896 ms 127680 KB Output is correct
74 Correct 1304 ms 127432 KB Output is correct
75 Correct 1590 ms 241252 KB Output is correct
76 Correct 978 ms 104484 KB Output is correct
77 Correct 1241 ms 174076 KB Output is correct
78 Correct 1401 ms 241544 KB Output is correct
79 Correct 1010 ms 35044 KB Output is correct
80 Correct 1316 ms 104616 KB Output is correct
81 Correct 1484 ms 174104 KB Output is correct
82 Correct 1607 ms 241500 KB Output is correct
83 Correct 707 ms 123352 KB Output is correct
84 Correct 134 ms 191144 KB Output is correct
85 Correct 766 ms 215688 KB Output is correct
86 Correct 802 ms 123396 KB Output is correct
87 Correct 1092 ms 123412 KB Output is correct
88 Correct 1188 ms 193144 KB Output is correct
89 Correct 852 ms 123284 KB Output is correct
90 Correct 1022 ms 216212 KB Output is correct
91 Correct 900 ms 53636 KB Output is correct
92 Correct 1156 ms 146536 KB Output is correct
93 Correct 1219 ms 216096 KB Output is correct
94 Correct 1298 ms 128300 KB Output is correct
95 Execution timed out 2019 ms 242336 KB Time limit exceeded
96 Halted 0 ms 0 KB -