답안 #257263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
257263 2020-08-04T03:02:25 Z maximath_1 Joker (BOI20_joker) C++11
100 / 100
268 ms 14312 KB
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <limits.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include <random>
#include <iostream>
#include <iomanip>
#include <unordered_map>
using namespace std;

int n, m, q, lst[200005], par[200005], off[200005];

void init(){
	for(int i = 1; i <= n; i ++){
		par[i] = -1;
		off[i] = 0;
	}
}

pair<int, int> gt(int x){
	int of = 0;
	while(par[x] >= 0){
		of ^= off[x];
		x = par[x];
	}
	return {x, of};
}

vector<array<int, 4> >md;
int uni(int _x, int _y){
	pair<int, int> x = gt(_x), y = gt(_y);
	if(x.first == y.first){
		if(x.second == y.second) return 0;
		md.push_back({-1, -1, -1, -1});
		return 1;
	}

	if(par[x.first] > par[y.first]) swap(x.first, y.first);
	md.push_back({x.first, y.first, par[x.first], par[y.first]});
	par[x.first] += par[y.first];
	par[y.first] = x.first;
	off[y.first] = x.second ^ y.second ^ 1;
	return 1;
}

void rollback(){
	auto a = md.back(); md.pop_back();
	if(a[0] != -1){
		par[a[0]] = a[2];
		par[a[1]] = a[3];
	}
}

int u[200005], v[200005];
bool upd(int idx){
	if(idx == m + 1) return 1;
	return uni(u[idx], v[idx]);
}
void restore(int _sz){
	while(md.size() > _sz) rollback();
}

void dnc(int xl, int xr, int yl, int yr){
//	cout << xl << " " << xr << " " << yl << " " << yr << endl;
	if(xl > xr) return;
	int xm = (xl + xr) / 2, rs = -1, sz = md.size();
	for(int i = xl; i < xm; i ++) if(!upd(i)){
		rs = yr; assert(rs == m + 1);
		break;
	}
	int sz2 = md.size();
	if(rs == -1){
		int i = yr;
		while(i > yl && upd(i)) i --;
		rs = i;
	}

	lst[xm] = rs;
	if(lst[xm] == m + 1){
		for(int i = xm + 1; i <= xr; i ++)
			lst[i] = rs;
	}else{
		restore(sz2);
		if(!upd(xm)){
			for(int i = xm + 1; i <= xr; i ++)
				lst[i] = m + 1;
		}else
			dnc(xm + 1, xr, lst[xm], yr);
	}

	restore(sz);
	for(int i = lst[xm] + 1; i <= yr; i ++) assert(upd(i));
	dnc(xl, xm - 1, yl, lst[xm]);
	restore(sz);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m >> q;
	for(int i = 1; i <= m; i ++)
		cin >> u[i] >> v[i];
	
	init();
	dnc(1, m, 1, m + 1);

	for(int l, r;q--;){
		cin >> l >> r;
		if(lst[l] <= r) cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}

Compilation message

Joker.cpp: In function 'void restore(int)':
Joker.cpp:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(md.size() > _sz) rollback();
        ~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 150 ms 5860 KB Output is correct
4 Correct 234 ms 11880 KB Output is correct
5 Correct 135 ms 7824 KB Output is correct
6 Correct 128 ms 5992 KB Output is correct
7 Correct 131 ms 5864 KB Output is correct
8 Correct 139 ms 5712 KB Output is correct
9 Correct 148 ms 5992 KB Output is correct
10 Correct 191 ms 6760 KB Output is correct
11 Correct 166 ms 5864 KB Output is correct
12 Correct 173 ms 6632 KB Output is correct
13 Correct 157 ms 5224 KB Output is correct
14 Correct 147 ms 5480 KB Output is correct
15 Correct 192 ms 6248 KB Output is correct
16 Correct 189 ms 6760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 150 ms 5860 KB Output is correct
30 Correct 234 ms 11880 KB Output is correct
31 Correct 135 ms 7824 KB Output is correct
32 Correct 128 ms 5992 KB Output is correct
33 Correct 131 ms 5864 KB Output is correct
34 Correct 139 ms 5712 KB Output is correct
35 Correct 148 ms 5992 KB Output is correct
36 Correct 191 ms 6760 KB Output is correct
37 Correct 166 ms 5864 KB Output is correct
38 Correct 173 ms 6632 KB Output is correct
39 Correct 157 ms 5224 KB Output is correct
40 Correct 147 ms 5480 KB Output is correct
41 Correct 192 ms 6248 KB Output is correct
42 Correct 189 ms 6760 KB Output is correct
43 Correct 161 ms 5864 KB Output is correct
44 Correct 268 ms 11880 KB Output is correct
45 Correct 205 ms 8160 KB Output is correct
46 Correct 122 ms 5864 KB Output is correct
47 Correct 139 ms 5864 KB Output is correct
48 Correct 176 ms 6120 KB Output is correct
49 Correct 194 ms 6760 KB Output is correct
50 Correct 168 ms 5608 KB Output is correct
51 Correct 169 ms 6128 KB Output is correct
52 Correct 176 ms 6752 KB Output is correct
53 Correct 153 ms 5228 KB Output is correct
54 Correct 178 ms 5736 KB Output is correct
55 Correct 192 ms 6120 KB Output is correct
56 Correct 200 ms 6760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 107 ms 5224 KB Output is correct
56 Correct 220 ms 14312 KB Output is correct
57 Correct 97 ms 10092 KB Output is correct
58 Correct 91 ms 7404 KB Output is correct
59 Correct 130 ms 7524 KB Output is correct
60 Correct 160 ms 8040 KB Output is correct
61 Correct 131 ms 7560 KB Output is correct
62 Correct 127 ms 8552 KB Output is correct
63 Correct 114 ms 6888 KB Output is correct
64 Correct 138 ms 7784 KB Output is correct
65 Correct 156 ms 8312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 0 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 0 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 1 ms 512 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 2 ms 512 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 512 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 512 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 150 ms 5860 KB Output is correct
56 Correct 234 ms 11880 KB Output is correct
57 Correct 135 ms 7824 KB Output is correct
58 Correct 128 ms 5992 KB Output is correct
59 Correct 131 ms 5864 KB Output is correct
60 Correct 139 ms 5712 KB Output is correct
61 Correct 148 ms 5992 KB Output is correct
62 Correct 191 ms 6760 KB Output is correct
63 Correct 166 ms 5864 KB Output is correct
64 Correct 173 ms 6632 KB Output is correct
65 Correct 157 ms 5224 KB Output is correct
66 Correct 147 ms 5480 KB Output is correct
67 Correct 192 ms 6248 KB Output is correct
68 Correct 189 ms 6760 KB Output is correct
69 Correct 161 ms 5864 KB Output is correct
70 Correct 268 ms 11880 KB Output is correct
71 Correct 205 ms 8160 KB Output is correct
72 Correct 122 ms 5864 KB Output is correct
73 Correct 139 ms 5864 KB Output is correct
74 Correct 176 ms 6120 KB Output is correct
75 Correct 194 ms 6760 KB Output is correct
76 Correct 168 ms 5608 KB Output is correct
77 Correct 169 ms 6128 KB Output is correct
78 Correct 176 ms 6752 KB Output is correct
79 Correct 153 ms 5228 KB Output is correct
80 Correct 178 ms 5736 KB Output is correct
81 Correct 192 ms 6120 KB Output is correct
82 Correct 200 ms 6760 KB Output is correct
83 Correct 107 ms 5224 KB Output is correct
84 Correct 220 ms 14312 KB Output is correct
85 Correct 97 ms 10092 KB Output is correct
86 Correct 91 ms 7404 KB Output is correct
87 Correct 130 ms 7524 KB Output is correct
88 Correct 160 ms 8040 KB Output is correct
89 Correct 131 ms 7560 KB Output is correct
90 Correct 127 ms 8552 KB Output is correct
91 Correct 114 ms 6888 KB Output is correct
92 Correct 138 ms 7784 KB Output is correct
93 Correct 156 ms 8312 KB Output is correct
94 Correct 171 ms 10728 KB Output is correct
95 Correct 207 ms 13208 KB Output is correct
96 Correct 154 ms 7772 KB Output is correct
97 Correct 144 ms 6108 KB Output is correct
98 Correct 154 ms 5996 KB Output is correct
99 Correct 172 ms 5736 KB Output is correct
100 Correct 183 ms 6884 KB Output is correct
101 Correct 185 ms 5732 KB Output is correct
102 Correct 205 ms 6248 KB Output is correct
103 Correct 215 ms 6896 KB Output is correct
104 Correct 176 ms 5480 KB Output is correct
105 Correct 216 ms 6120 KB Output is correct
106 Correct 214 ms 6632 KB Output is correct
107 Correct 148 ms 8164 KB Output is correct
108 Correct 179 ms 5864 KB Output is correct
109 Correct 160 ms 5864 KB Output is correct
110 Correct 170 ms 5864 KB Output is correct
111 Correct 172 ms 5864 KB Output is correct
112 Correct 179 ms 5868 KB Output is correct
113 Correct 173 ms 5868 KB Output is correct
114 Correct 159 ms 5816 KB Output is correct
115 Correct 184 ms 5864 KB Output is correct
116 Correct 171 ms 5756 KB Output is correct