Submission #973448

# Submission time Handle Problem Language Result Execution time Memory
973448 2024-05-02T02:37:51 Z cot7302 Joker (BOI20_joker) C++17
100 / 100
343 ms 16560 KB
#include <bits/stdc++.h>
using namespace std;

struct disjoint_set {
    int n, odd_cir;
    vector<int> _, odd_cir_op;
    vector<tuple<int, int, int>> op;
    disjoint_set(int n) : n(n), odd_cir(0), _(2 * n + 1, -1), odd_cir_op(), op() {}

    int root(int x) { while (_[x] > 0) x = _[x]; return x; }

    void __join(int a, int b) {
        a = root(a), b = root(b);
        if (a == b) return;
        if (_[a] > _[b]) swap(a, b);
        op.emplace_back(a, b, _[b]);
        _[a] += _[b];
        _[b] = a;
    }

    void join(int a, int b) {
        __join(a, b + n);
        __join(a + n, b);
        odd_cir += odd_cir_op.emplace_back(root(a) == root(b));
    }

    void join(pair<int, int> x) {
        auto [a, b] = x;
        join(a, b);
    }

    bool is_bipartite() const {
        return !odd_cir;
    }

    void roll_back(int cnta, int cntb) {
        while (cnta != (int)size(op)) {
            auto [a, b, sz] = op.back();
            _[a] -= sz;
            _[b] = sz;
            op.pop_back();
        }
        while (cntb != (int)size(odd_cir_op)) {
            odd_cir -= odd_cir_op.back();
            odd_cir_op.pop_back();
        }
    }

    void roll_back(pair<int, int> x) {
        roll_back(x.first, x.second);
    }

    pair<int, int> snapshot() const {
        return {(int)size(op), (int)size(odd_cir_op)};
    }
};

pair<int, int> edges[200001];

int ans[200001];

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, m, q; cin >> n >> m >> q;
    for (int i = 1; i <= m; i++) cin >> edges[i].first >> edges[i].second;
    disjoint_set dsu(n);
    for (int i = 1; i <= m; i++) dsu.join(edges[i]);
    if (dsu.is_bipartite()) {
        while (q--) cout << "NO\n";
        return 0;
    }
    dsu.roll_back(0, 0);
    auto solve = [&](auto&& f, int l, int r, int ql, int qr) -> void {
        if (l > r) return;
        int mid = (l + r) >> 1;
        auto snap = dsu.snapshot();
        for (int i = l; i < mid; i++) dsu.join(edges[i]);
        int opt = qr;
        while (dsu.is_bipartite()) dsu.join(edges[opt--]);
        ans[mid] = opt;
        dsu.roll_back(snap);
        snap = dsu.snapshot();
        for (int i = opt + 1; i <= qr; i++) dsu.join(edges[i]);
        f(f, l, mid - 1, ql, opt);
        dsu.roll_back(snap);
        snap = dsu.snapshot();
        for (int i = l; i <= mid; i++) dsu.join(edges[i]);
        f(f, mid + 1, r, opt, qr);
        dsu.roll_back(snap);
    };

    solve(solve, 1, m, 0, m);
    //for (int i = 0; i < m; i++) cout << ans[i] << " \n"[i == m - 1];
    for (int l, r; q--; ) {
        cin >> l >> r;
        cout << ((r <= ans[l]) ? "YES\n" : "NO\n");
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2552 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2536 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2504 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2552 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2536 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2504 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2524 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 2 ms 2524 KB Output is correct
35 Correct 3 ms 2652 KB Output is correct
36 Correct 2 ms 2396 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 1 ms 2552 KB Output is correct
39 Correct 2 ms 2652 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 2 ms 2396 KB Output is correct
43 Correct 3 ms 2396 KB Output is correct
44 Correct 2 ms 2616 KB Output is correct
45 Correct 3 ms 2520 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 2 ms 2396 KB Output is correct
49 Correct 2 ms 2652 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2396 KB Output is correct
52 Correct 2 ms 2392 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 2 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 171 ms 8452 KB Output is correct
4 Correct 44 ms 12392 KB Output is correct
5 Correct 154 ms 12616 KB Output is correct
6 Correct 207 ms 10640 KB Output is correct
7 Correct 222 ms 10612 KB Output is correct
8 Correct 247 ms 8940 KB Output is correct
9 Correct 253 ms 10524 KB Output is correct
10 Correct 294 ms 15332 KB Output is correct
11 Correct 219 ms 10732 KB Output is correct
12 Correct 228 ms 14660 KB Output is correct
13 Correct 259 ms 7532 KB Output is correct
14 Correct 244 ms 9192 KB Output is correct
15 Correct 299 ms 15612 KB Output is correct
16 Correct 280 ms 14968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2552 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2536 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2504 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 171 ms 8452 KB Output is correct
30 Correct 44 ms 12392 KB Output is correct
31 Correct 154 ms 12616 KB Output is correct
32 Correct 207 ms 10640 KB Output is correct
33 Correct 222 ms 10612 KB Output is correct
34 Correct 247 ms 8940 KB Output is correct
35 Correct 253 ms 10524 KB Output is correct
36 Correct 294 ms 15332 KB Output is correct
37 Correct 219 ms 10732 KB Output is correct
38 Correct 228 ms 14660 KB Output is correct
39 Correct 259 ms 7532 KB Output is correct
40 Correct 244 ms 9192 KB Output is correct
41 Correct 299 ms 15612 KB Output is correct
42 Correct 280 ms 14968 KB Output is correct
43 Correct 171 ms 10628 KB Output is correct
44 Correct 38 ms 15076 KB Output is correct
45 Correct 218 ms 14948 KB Output is correct
46 Correct 210 ms 10580 KB Output is correct
47 Correct 212 ms 11088 KB Output is correct
48 Correct 273 ms 10396 KB Output is correct
49 Correct 294 ms 14316 KB Output is correct
50 Correct 196 ms 10140 KB Output is correct
51 Correct 233 ms 14452 KB Output is correct
52 Correct 235 ms 14828 KB Output is correct
53 Correct 247 ms 7880 KB Output is correct
54 Correct 280 ms 9832 KB Output is correct
55 Correct 296 ms 14640 KB Output is correct
56 Correct 343 ms 15284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2552 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2536 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2504 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2524 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 2 ms 2524 KB Output is correct
35 Correct 3 ms 2652 KB Output is correct
36 Correct 2 ms 2396 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 1 ms 2552 KB Output is correct
39 Correct 2 ms 2652 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 2 ms 2396 KB Output is correct
43 Correct 3 ms 2396 KB Output is correct
44 Correct 2 ms 2616 KB Output is correct
45 Correct 3 ms 2520 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 2 ms 2396 KB Output is correct
49 Correct 2 ms 2652 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2396 KB Output is correct
52 Correct 2 ms 2392 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 2 ms 2652 KB Output is correct
55 Correct 140 ms 10064 KB Output is correct
56 Correct 36 ms 14476 KB Output is correct
57 Correct 136 ms 15252 KB Output is correct
58 Correct 209 ms 9980 KB Output is correct
59 Correct 262 ms 10320 KB Output is correct
60 Correct 298 ms 14420 KB Output is correct
61 Correct 222 ms 10504 KB Output is correct
62 Correct 215 ms 15044 KB Output is correct
63 Correct 217 ms 7912 KB Output is correct
64 Correct 258 ms 10728 KB Output is correct
65 Correct 293 ms 15624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2552 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2536 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2504 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 2 ms 2652 KB Output is correct
31 Correct 2 ms 2524 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 2 ms 2396 KB Output is correct
34 Correct 2 ms 2524 KB Output is correct
35 Correct 3 ms 2652 KB Output is correct
36 Correct 2 ms 2396 KB Output is correct
37 Correct 2 ms 2652 KB Output is correct
38 Correct 1 ms 2552 KB Output is correct
39 Correct 2 ms 2652 KB Output is correct
40 Correct 2 ms 2396 KB Output is correct
41 Correct 2 ms 2396 KB Output is correct
42 Correct 2 ms 2396 KB Output is correct
43 Correct 3 ms 2396 KB Output is correct
44 Correct 2 ms 2616 KB Output is correct
45 Correct 3 ms 2520 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2396 KB Output is correct
48 Correct 2 ms 2396 KB Output is correct
49 Correct 2 ms 2652 KB Output is correct
50 Correct 2 ms 2652 KB Output is correct
51 Correct 2 ms 2396 KB Output is correct
52 Correct 2 ms 2392 KB Output is correct
53 Correct 2 ms 2652 KB Output is correct
54 Correct 2 ms 2652 KB Output is correct
55 Correct 171 ms 8452 KB Output is correct
56 Correct 44 ms 12392 KB Output is correct
57 Correct 154 ms 12616 KB Output is correct
58 Correct 207 ms 10640 KB Output is correct
59 Correct 222 ms 10612 KB Output is correct
60 Correct 247 ms 8940 KB Output is correct
61 Correct 253 ms 10524 KB Output is correct
62 Correct 294 ms 15332 KB Output is correct
63 Correct 219 ms 10732 KB Output is correct
64 Correct 228 ms 14660 KB Output is correct
65 Correct 259 ms 7532 KB Output is correct
66 Correct 244 ms 9192 KB Output is correct
67 Correct 299 ms 15612 KB Output is correct
68 Correct 280 ms 14968 KB Output is correct
69 Correct 171 ms 10628 KB Output is correct
70 Correct 38 ms 15076 KB Output is correct
71 Correct 218 ms 14948 KB Output is correct
72 Correct 210 ms 10580 KB Output is correct
73 Correct 212 ms 11088 KB Output is correct
74 Correct 273 ms 10396 KB Output is correct
75 Correct 294 ms 14316 KB Output is correct
76 Correct 196 ms 10140 KB Output is correct
77 Correct 233 ms 14452 KB Output is correct
78 Correct 235 ms 14828 KB Output is correct
79 Correct 247 ms 7880 KB Output is correct
80 Correct 280 ms 9832 KB Output is correct
81 Correct 296 ms 14640 KB Output is correct
82 Correct 343 ms 15284 KB Output is correct
83 Correct 140 ms 10064 KB Output is correct
84 Correct 36 ms 14476 KB Output is correct
85 Correct 136 ms 15252 KB Output is correct
86 Correct 209 ms 9980 KB Output is correct
87 Correct 262 ms 10320 KB Output is correct
88 Correct 298 ms 14420 KB Output is correct
89 Correct 222 ms 10504 KB Output is correct
90 Correct 215 ms 15044 KB Output is correct
91 Correct 217 ms 7912 KB Output is correct
92 Correct 258 ms 10728 KB Output is correct
93 Correct 293 ms 15624 KB Output is correct
94 Correct 178 ms 12436 KB Output is correct
95 Correct 207 ms 16560 KB Output is correct
96 Correct 174 ms 14816 KB Output is correct
97 Correct 224 ms 12384 KB Output is correct
98 Correct 239 ms 13060 KB Output is correct
99 Correct 253 ms 10988 KB Output is correct
100 Correct 279 ms 15844 KB Output is correct
101 Correct 210 ms 12208 KB Output is correct
102 Correct 243 ms 14692 KB Output is correct
103 Correct 251 ms 15940 KB Output is correct
104 Correct 245 ms 10220 KB Output is correct
105 Correct 295 ms 13124 KB Output is correct
106 Correct 298 ms 16096 KB Output is correct
107 Correct 147 ms 16020 KB Output is correct
108 Correct 165 ms 12004 KB Output is correct
109 Correct 162 ms 12004 KB Output is correct
110 Correct 191 ms 12800 KB Output is correct
111 Correct 164 ms 12524 KB Output is correct
112 Correct 161 ms 12772 KB Output is correct
113 Correct 197 ms 12180 KB Output is correct
114 Correct 166 ms 12004 KB Output is correct
115 Correct 184 ms 12080 KB Output is correct
116 Correct 167 ms 12096 KB Output is correct