답안 #1017835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017835 2024-07-09T10:34:53 Z VMaksimoski008 Joker (BOI20_joker) C++17
100 / 100
207 ms 25796 KB
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;

array<int, 2> E[200008];
int last[200008];
 
struct Disjoint_Set_Union {
	static const int N = 2e5;
	int par[N + 8], dis[N + 8], sz[N + 8];
	vector<pair<int*, int>> history; int is_bi = 1;
	Disjoint_Set_Union() {
		iota(par, par + N + 8, 0);
		fill(dis, dis + N + 8, 0);
		fill(sz, sz + N + 8, 1);
	}
	pair<int, int> pu, pv; int du, dv;
	pair<int, int> find(int u) {
		du = 0;
		while (par[u] != u) du ^= dis[u], u = par[u];
		return {u, du};
	}
	void uni(int u, int v) {
		pu = find(u); pv = find(v);
		u = pu.first; du = pu.second; v = pv.first; dv = pv.second;
		if (u == v) {
			if (du == dv) history.push_back({&is_bi, is_bi}), is_bi = 0;
			return;
		}
		if (sz[u] < sz[v]) swap(u, v);
		history.push_back({par + v, par[v]});
		history.push_back({dis + v, dis[v]});
		history.push_back({sz + u, sz[u]});
		par[v] = u; dis[v] = du ^ dv ^ 1; sz[u] += sz[v];
	}
	int snap() {return history.size();}
	void roll(int snapshot) {
		while (history.size() > snapshot) {
			*history.back().first = history.back().second;
			history.pop_back();
		}
	}
} dsu;

void f(int l, int r, int tl, int tr) {
    if(l > r) return ;
    int mid = (l + r) / 2, ss = dsu.snap();

    for(int i=l; i<mid; i++) dsu.uni(E[i][0], E[i][1]);
    int ss2 = dsu.snap();

    for(int i=tr; i>=max(mid, tl); i--) {
        if(!dsu.is_bi) {
            last[mid] = i;
            break;
        }

        dsu.uni(E[i][0], E[i][1]);
    }

    if(!last[mid]) last[mid] = mid - 1;

    dsu.roll(ss2);
    dsu.uni(E[mid][0], E[mid][1]);
    f(mid+1, r, last[mid], tr);
    dsu.roll(ss);
    for(int i=tr; i>last[mid]; i--) dsu.uni(E[i][0], E[i][1]);
    f(l, mid-1, tl, last[mid]);
    dsu.roll(ss);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    int n, m, q;
    cin >> n >> m >> q;

    for(int i=1; i<=m; i++) cin >> E[i][0] >> E[i][1];

    f(1, m, 1, m);
    while(q--) {
        int l, r;
        cin >> l >> r;
        cout << (last[l] < r ? "NO" : "YES") << '\n';
    }
    return 0;
}

Compilation message

Joker.cpp: In member function 'void Disjoint_Set_Union::roll(int)':
Joker.cpp:50:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int*, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |   while (history.size() > snapshot) {
      |          ~~~~~~~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4764 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 2 ms 4512 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4764 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 2 ms 4512 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 2 ms 4700 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 4700 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4952 KB Output is correct
40 Correct 3 ms 4700 KB Output is correct
41 Correct 2 ms 4700 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 3 ms 4700 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 3 ms 4700 KB Output is correct
48 Correct 2 ms 4700 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4760 KB Output is correct
52 Correct 2 ms 4756 KB Output is correct
53 Correct 2 ms 4956 KB Output is correct
54 Correct 2 ms 4764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 129 ms 17872 KB Output is correct
4 Correct 199 ms 25024 KB Output is correct
5 Correct 109 ms 24516 KB Output is correct
6 Correct 115 ms 16584 KB Output is correct
7 Correct 118 ms 17860 KB Output is correct
8 Correct 119 ms 12960 KB Output is correct
9 Correct 144 ms 17096 KB Output is correct
10 Correct 166 ms 17588 KB Output is correct
11 Correct 131 ms 16068 KB Output is correct
12 Correct 145 ms 17588 KB Output is correct
13 Correct 123 ms 11460 KB Output is correct
14 Correct 119 ms 13500 KB Output is correct
15 Correct 165 ms 17864 KB Output is correct
16 Correct 178 ms 18140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4764 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 2 ms 4512 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 129 ms 17872 KB Output is correct
30 Correct 199 ms 25024 KB Output is correct
31 Correct 109 ms 24516 KB Output is correct
32 Correct 115 ms 16584 KB Output is correct
33 Correct 118 ms 17860 KB Output is correct
34 Correct 119 ms 12960 KB Output is correct
35 Correct 144 ms 17096 KB Output is correct
36 Correct 166 ms 17588 KB Output is correct
37 Correct 131 ms 16068 KB Output is correct
38 Correct 145 ms 17588 KB Output is correct
39 Correct 123 ms 11460 KB Output is correct
40 Correct 119 ms 13500 KB Output is correct
41 Correct 165 ms 17864 KB Output is correct
42 Correct 178 ms 18140 KB Output is correct
43 Correct 127 ms 17332 KB Output is correct
44 Correct 207 ms 25024 KB Output is correct
45 Correct 171 ms 25796 KB Output is correct
46 Correct 111 ms 17360 KB Output is correct
47 Correct 112 ms 17716 KB Output is correct
48 Correct 155 ms 16652 KB Output is correct
49 Correct 170 ms 18156 KB Output is correct
50 Correct 123 ms 17104 KB Output is correct
51 Correct 138 ms 17624 KB Output is correct
52 Correct 152 ms 18356 KB Output is correct
53 Correct 114 ms 11780 KB Output is correct
54 Correct 136 ms 16848 KB Output is correct
55 Correct 185 ms 18008 KB Output is correct
56 Correct 177 ms 18388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4764 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 2 ms 4512 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 2 ms 4700 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 4700 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4952 KB Output is correct
40 Correct 3 ms 4700 KB Output is correct
41 Correct 2 ms 4700 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 3 ms 4700 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 3 ms 4700 KB Output is correct
48 Correct 2 ms 4700 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4760 KB Output is correct
52 Correct 2 ms 4756 KB Output is correct
53 Correct 2 ms 4956 KB Output is correct
54 Correct 2 ms 4764 KB Output is correct
55 Correct 102 ms 16068 KB Output is correct
56 Correct 185 ms 24516 KB Output is correct
57 Correct 82 ms 24516 KB Output is correct
58 Correct 92 ms 16324 KB Output is correct
59 Correct 113 ms 16336 KB Output is correct
60 Correct 154 ms 16072 KB Output is correct
61 Correct 117 ms 16068 KB Output is correct
62 Correct 121 ms 17616 KB Output is correct
63 Correct 88 ms 13000 KB Output is correct
64 Correct 128 ms 17256 KB Output is correct
65 Correct 147 ms 17868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 2 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4764 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 2 ms 4512 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4696 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 2 ms 4700 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 4700 KB Output is correct
37 Correct 2 ms 4956 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4952 KB Output is correct
40 Correct 3 ms 4700 KB Output is correct
41 Correct 2 ms 4700 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 3 ms 4700 KB Output is correct
44 Correct 2 ms 5212 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 3 ms 4700 KB Output is correct
48 Correct 2 ms 4700 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 4760 KB Output is correct
52 Correct 2 ms 4756 KB Output is correct
53 Correct 2 ms 4956 KB Output is correct
54 Correct 2 ms 4764 KB Output is correct
55 Correct 129 ms 17872 KB Output is correct
56 Correct 199 ms 25024 KB Output is correct
57 Correct 109 ms 24516 KB Output is correct
58 Correct 115 ms 16584 KB Output is correct
59 Correct 118 ms 17860 KB Output is correct
60 Correct 119 ms 12960 KB Output is correct
61 Correct 144 ms 17096 KB Output is correct
62 Correct 166 ms 17588 KB Output is correct
63 Correct 131 ms 16068 KB Output is correct
64 Correct 145 ms 17588 KB Output is correct
65 Correct 123 ms 11460 KB Output is correct
66 Correct 119 ms 13500 KB Output is correct
67 Correct 165 ms 17864 KB Output is correct
68 Correct 178 ms 18140 KB Output is correct
69 Correct 127 ms 17332 KB Output is correct
70 Correct 207 ms 25024 KB Output is correct
71 Correct 171 ms 25796 KB Output is correct
72 Correct 111 ms 17360 KB Output is correct
73 Correct 112 ms 17716 KB Output is correct
74 Correct 155 ms 16652 KB Output is correct
75 Correct 170 ms 18156 KB Output is correct
76 Correct 123 ms 17104 KB Output is correct
77 Correct 138 ms 17624 KB Output is correct
78 Correct 152 ms 18356 KB Output is correct
79 Correct 114 ms 11780 KB Output is correct
80 Correct 136 ms 16848 KB Output is correct
81 Correct 185 ms 18008 KB Output is correct
82 Correct 177 ms 18388 KB Output is correct
83 Correct 102 ms 16068 KB Output is correct
84 Correct 185 ms 24516 KB Output is correct
85 Correct 82 ms 24516 KB Output is correct
86 Correct 92 ms 16324 KB Output is correct
87 Correct 113 ms 16336 KB Output is correct
88 Correct 154 ms 16072 KB Output is correct
89 Correct 117 ms 16068 KB Output is correct
90 Correct 121 ms 17616 KB Output is correct
91 Correct 88 ms 13000 KB Output is correct
92 Correct 128 ms 17256 KB Output is correct
93 Correct 147 ms 17868 KB Output is correct
94 Correct 135 ms 17336 KB Output is correct
95 Correct 161 ms 24516 KB Output is correct
96 Correct 128 ms 25036 KB Output is correct
97 Correct 123 ms 17864 KB Output is correct
98 Correct 121 ms 17128 KB Output is correct
99 Correct 126 ms 14312 KB Output is correct
100 Correct 167 ms 19124 KB Output is correct
101 Correct 125 ms 17080 KB Output is correct
102 Correct 151 ms 17588 KB Output is correct
103 Correct 167 ms 19100 KB Output is correct
104 Correct 118 ms 13424 KB Output is correct
105 Correct 157 ms 18004 KB Output is correct
106 Correct 176 ms 18652 KB Output is correct
107 Correct 119 ms 25792 KB Output is correct
108 Correct 131 ms 18136 KB Output is correct
109 Correct 147 ms 18140 KB Output is correct
110 Correct 140 ms 17332 KB Output is correct
111 Correct 130 ms 17184 KB Output is correct
112 Correct 133 ms 17092 KB Output is correct
113 Correct 130 ms 17380 KB Output is correct
114 Correct 133 ms 18620 KB Output is correct
115 Correct 131 ms 18356 KB Output is correct
116 Correct 130 ms 18100 KB Output is correct