Submission #1049663

# Submission time Handle Problem Language Result Execution time Memory
1049663 2024-08-09T03:42:35 Z shiomusubi496 Joker (BOI20_joker) C++17
39 / 100
2000 ms 24256 KB
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)

using namespace std;

using ll = long long;

template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }

class UndoableUF {
    int n;
    bool flag = true;
    vector<int> par;
    vector<tuple<int, int, bool>> history;

public:
    UndoableUF(int n_) : n(n_ / 2), par(n_, -1) {}
    int find(int x) { return par[x] < 0 ? x : find(par[x]); }
    bool merge(int x, int y) {
        x = find(x), y = find(y);
        history.emplace_back(x, par[x], flag);
        history.emplace_back(y, par[y], flag);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        if (same(x, (x + n) % (2 * n))) flag = false;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    void undo() {
        auto [x, px, _] = history.back(); history.pop_back();
        auto [y, py, f] = history.back(); history.pop_back();
        par[x] = px;
        par[y] = py;
        flag = f;
    }
    void snapshot() { history.clear(); }
    void rollback() {
        while (!history.empty()) undo();
    }
    bool is_bip() { return flag; }
};

int main() {
    int N, M, Q; cin >> N >> M >> Q;
    vector<pair<int, int>> A(M);
    rep (i, M) {
        cin >> A[i].first >> A[i].second;
        --A[i].first, --A[i].second;
    }
    vector<array<int, 3>> B(Q);
    rep (i, Q) {
        cin >> B[i][0] >> B[i][1];
        --B[i][0];
        B[i][2] = i;
    }
    int block = 1;
    sort(all(B), [&](auto a, auto b) {
        if (a[0] / block != b[0] / block) return a[0] < b[0];
        return a[1] > b[1];
    });
    vector<bool> ans(Q);
    int curl = block, curr = M;
    UndoableUF uf(2 * N);
    for (auto [l, r, k] : B) {
        while (curl <= l) {
            uf.rollback();
            rep2 (i, curl - block, curl) {
                if (i >= M) break;
                uf.merge(A[i].first, A[i].second + N);
                uf.merge(A[i].first + N, A[i].second);
            }
            uf.snapshot();
            curl += block;
            curr = M;
        }
        assert(curr >= r);
        rrep2 (i, r, curr) {
            uf.merge(A[i].first, A[i].second + N);
            uf.merge(A[i].first + N, A[i].second);
        }
        curr = r;
        rep2 (i, curl - block, l) {
            uf.merge(A[i].first, A[i].second + N);
            uf.merge(A[i].first + N, A[i].second);
        }
        ans[k] = uf.is_bip();
        rep2 (i, curl - block, l) uf.undo(), uf.undo();
    }
    rep (i, Q) puts(ans[i] ? "NO" : "YES");
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 388 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 388 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 9 ms 604 KB Output is correct
31 Correct 9 ms 604 KB Output is correct
32 Correct 8 ms 600 KB Output is correct
33 Correct 6 ms 664 KB Output is correct
34 Correct 9 ms 676 KB Output is correct
35 Correct 11 ms 604 KB Output is correct
36 Correct 6 ms 604 KB Output is correct
37 Correct 17 ms 680 KB Output is correct
38 Correct 23 ms 604 KB Output is correct
39 Correct 7 ms 604 KB Output is correct
40 Correct 6 ms 604 KB Output is correct
41 Correct 6 ms 604 KB Output is correct
42 Correct 6 ms 668 KB Output is correct
43 Correct 23 ms 604 KB Output is correct
44 Correct 23 ms 604 KB Output is correct
45 Correct 21 ms 672 KB Output is correct
46 Correct 21 ms 680 KB Output is correct
47 Correct 7 ms 604 KB Output is correct
48 Correct 8 ms 668 KB Output is correct
49 Correct 11 ms 604 KB Output is correct
50 Correct 9 ms 680 KB Output is correct
51 Correct 11 ms 604 KB Output is correct
52 Correct 9 ms 664 KB Output is correct
53 Correct 9 ms 672 KB Output is correct
54 Correct 14 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 122 ms 19008 KB Output is correct
4 Correct 120 ms 20016 KB Output is correct
5 Correct 125 ms 19140 KB Output is correct
6 Correct 129 ms 19388 KB Output is correct
7 Correct 123 ms 18368 KB Output is correct
8 Correct 112 ms 18876 KB Output is correct
9 Correct 112 ms 18472 KB Output is correct
10 Correct 122 ms 18620 KB Output is correct
11 Correct 119 ms 19392 KB Output is correct
12 Correct 124 ms 19776 KB Output is correct
13 Correct 123 ms 18496 KB Output is correct
14 Correct 128 ms 17852 KB Output is correct
15 Correct 130 ms 18624 KB Output is correct
16 Correct 126 ms 19132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 388 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 122 ms 19008 KB Output is correct
30 Correct 120 ms 20016 KB Output is correct
31 Correct 125 ms 19140 KB Output is correct
32 Correct 129 ms 19388 KB Output is correct
33 Correct 123 ms 18368 KB Output is correct
34 Correct 112 ms 18876 KB Output is correct
35 Correct 112 ms 18472 KB Output is correct
36 Correct 122 ms 18620 KB Output is correct
37 Correct 119 ms 19392 KB Output is correct
38 Correct 124 ms 19776 KB Output is correct
39 Correct 123 ms 18496 KB Output is correct
40 Correct 128 ms 17852 KB Output is correct
41 Correct 130 ms 18624 KB Output is correct
42 Correct 126 ms 19132 KB Output is correct
43 Correct 1067 ms 23728 KB Output is correct
44 Correct 1331 ms 22828 KB Output is correct
45 Correct 1346 ms 23740 KB Output is correct
46 Correct 1447 ms 23624 KB Output is correct
47 Correct 1679 ms 22428 KB Output is correct
48 Correct 1997 ms 22436 KB Output is correct
49 Correct 1935 ms 24256 KB Output is correct
50 Correct 1598 ms 23228 KB Output is correct
51 Correct 1499 ms 22176 KB Output is correct
52 Correct 1605 ms 23492 KB Output is correct
53 Correct 1559 ms 22460 KB Output is correct
54 Execution timed out 2021 ms 22700 KB Time limit exceeded
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 388 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 9 ms 604 KB Output is correct
31 Correct 9 ms 604 KB Output is correct
32 Correct 8 ms 600 KB Output is correct
33 Correct 6 ms 664 KB Output is correct
34 Correct 9 ms 676 KB Output is correct
35 Correct 11 ms 604 KB Output is correct
36 Correct 6 ms 604 KB Output is correct
37 Correct 17 ms 680 KB Output is correct
38 Correct 23 ms 604 KB Output is correct
39 Correct 7 ms 604 KB Output is correct
40 Correct 6 ms 604 KB Output is correct
41 Correct 6 ms 604 KB Output is correct
42 Correct 6 ms 668 KB Output is correct
43 Correct 23 ms 604 KB Output is correct
44 Correct 23 ms 604 KB Output is correct
45 Correct 21 ms 672 KB Output is correct
46 Correct 21 ms 680 KB Output is correct
47 Correct 7 ms 604 KB Output is correct
48 Correct 8 ms 668 KB Output is correct
49 Correct 11 ms 604 KB Output is correct
50 Correct 9 ms 680 KB Output is correct
51 Correct 11 ms 604 KB Output is correct
52 Correct 9 ms 664 KB Output is correct
53 Correct 9 ms 672 KB Output is correct
54 Correct 14 ms 604 KB Output is correct
55 Correct 1549 ms 16060 KB Output is correct
56 Execution timed out 2070 ms 20416 KB Time limit exceeded
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 388 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 9 ms 604 KB Output is correct
31 Correct 9 ms 604 KB Output is correct
32 Correct 8 ms 600 KB Output is correct
33 Correct 6 ms 664 KB Output is correct
34 Correct 9 ms 676 KB Output is correct
35 Correct 11 ms 604 KB Output is correct
36 Correct 6 ms 604 KB Output is correct
37 Correct 17 ms 680 KB Output is correct
38 Correct 23 ms 604 KB Output is correct
39 Correct 7 ms 604 KB Output is correct
40 Correct 6 ms 604 KB Output is correct
41 Correct 6 ms 604 KB Output is correct
42 Correct 6 ms 668 KB Output is correct
43 Correct 23 ms 604 KB Output is correct
44 Correct 23 ms 604 KB Output is correct
45 Correct 21 ms 672 KB Output is correct
46 Correct 21 ms 680 KB Output is correct
47 Correct 7 ms 604 KB Output is correct
48 Correct 8 ms 668 KB Output is correct
49 Correct 11 ms 604 KB Output is correct
50 Correct 9 ms 680 KB Output is correct
51 Correct 11 ms 604 KB Output is correct
52 Correct 9 ms 664 KB Output is correct
53 Correct 9 ms 672 KB Output is correct
54 Correct 14 ms 604 KB Output is correct
55 Correct 122 ms 19008 KB Output is correct
56 Correct 120 ms 20016 KB Output is correct
57 Correct 125 ms 19140 KB Output is correct
58 Correct 129 ms 19388 KB Output is correct
59 Correct 123 ms 18368 KB Output is correct
60 Correct 112 ms 18876 KB Output is correct
61 Correct 112 ms 18472 KB Output is correct
62 Correct 122 ms 18620 KB Output is correct
63 Correct 119 ms 19392 KB Output is correct
64 Correct 124 ms 19776 KB Output is correct
65 Correct 123 ms 18496 KB Output is correct
66 Correct 128 ms 17852 KB Output is correct
67 Correct 130 ms 18624 KB Output is correct
68 Correct 126 ms 19132 KB Output is correct
69 Correct 1067 ms 23728 KB Output is correct
70 Correct 1331 ms 22828 KB Output is correct
71 Correct 1346 ms 23740 KB Output is correct
72 Correct 1447 ms 23624 KB Output is correct
73 Correct 1679 ms 22428 KB Output is correct
74 Correct 1997 ms 22436 KB Output is correct
75 Correct 1935 ms 24256 KB Output is correct
76 Correct 1598 ms 23228 KB Output is correct
77 Correct 1499 ms 22176 KB Output is correct
78 Correct 1605 ms 23492 KB Output is correct
79 Correct 1559 ms 22460 KB Output is correct
80 Execution timed out 2021 ms 22700 KB Time limit exceeded
81 Halted 0 ms 0 KB -