Submission #1014666

# Submission time Handle Problem Language Result Execution time Memory
1014666 2024-07-05T09:06:04 Z MODDI Joker (BOI20_joker) C++14
49 / 100
2000 ms 24524 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")

using pii = pair<int, int>;

struct DSU {
    int n;
    vector<pii> par;
    vector<int> size, bi;

    DSU(int _n) {
        n = _n;
        par.resize(n+1);
        size.resize(n+1, 1);
        bi.resize(n+1, 1);
        for(int i=1; i<=n; i++) par[i] = { i, 0 };
    }

    pii find(int u) {
        if(u == par[u].first) return par[u];
        int p = par[u].second;
        par[u] = find(par[u].first);
        par[u].second ^= p;
        return par[u];
    }

    bool uni(int a, int b) {
        auto pa = find(a), pb = find(b);

        if(pa.first == pb.first) {
            if(pa.second == pb.second) bi[pa.first] = 0;
            return 0;
        }

        if(size[pa.first] < size[pb.first]) swap(pa, pb);
        size[pa.first] += size[pb.first];
        par[pb.first] = { pa.first, pa.second ^ pb.second ^ 1 };
        bi[pa.first] &= bi[pb.first];

        return 1;
    }

    int getBi(int u) { return bi[find(u).first]; }

    void reset() {
        for(int i=1; i<=n; i++) {
            par[i] = { i, 0 };
            size[i] = 1;
            bi[i] = 1;
        }
    }
};

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

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

    vector<array<int, 2> > edges(m+1);
    for(int i=1; i<=m; i++) cin >> edges[i][0] >> edges[i][1];

    if(n <= 2000 && m <= 2000 && q <= 2000) {
        while(q--) {
            int l, r;
            cin >> l >> r;

            DSU dsu(n);
            int bi = 1;
            for(int i=1; i<=m; i++) {
                if(l <= i && i <= r) continue;
                dsu.uni(edges[i][0], edges[i][1]);
                if(!dsu.getBi(edges[i][0])) {
                    bi = 0;
                    break;
                }
            }

            cout << (bi ? "NO" : "YES") << '\n';
        }

        return 0;
    }

    int mx = 0;
    vector<int> ans(q);
    vector<int> qus[m+1];
    vector<pii> qus2[m+1];
    for(int i=0; i<q; i++) {
        int l, r;
        cin >> l >> r;
        mx = max(mx, l);
        qus[r].push_back(i);
        qus2[l].push_back({ r, i });
    }

    if(mx == 1) {
        DSU dsu(n);
        int bi = 1;
        for(int i=m; i>=1; i--) {
            for(int &id : qus[i]) ans[id] = bi;
            dsu.uni(edges[i][0], edges[i][1]);
            if(!dsu.getBi(edges[i][0])) bi = 0;
        }

        for(int &x : ans) cout << (x ? "NO" : "YES") << '\n';
        return 0;
    }

    int bi2=1;
    DSU dsu(n);
    for(int i=1; i<=mx; i++) {
        if(qus2[i].size() == 0) continue;
        if(bi2 == 0) continue;

        sort(qus2[i].begin(), qus2[i].end());
        int bi = 1, p = qus2[i].size() - 1;
        dsu.reset();

        for(int j=1; j<i&&bi2; j++) {
            dsu.uni(edges[j][0], edges[j][1]);
            if(!dsu.getBi(edges[j][0])) {
                bi = 0;
                bi2 = 0;
                break;
            }
        }

        if(!bi2) bi = 0;
        for(int j=m; j>=i&&bi; j--) {
            while(p >= 0 && qus2[i][p].first == j) {
                ans[qus2[i][p].second] = bi;
                p--;
            }

            dsu.uni(edges[j][0], edges[j][1]);
            if(!dsu.getBi(edges[j][0])) bi = 0;
        }

    }

    for(int &x : ans) cout << (x ? "NO" : "YES") << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 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 1 ms 348 KB Output is correct
19 Correct 1 ms 452 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 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 1 ms 348 KB Output is correct
19 Correct 1 ms 452 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 19 ms 468 KB Output is correct
30 Correct 22 ms 348 KB Output is correct
31 Correct 20 ms 348 KB Output is correct
32 Correct 12 ms 532 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 18 ms 540 KB Output is correct
35 Correct 29 ms 540 KB Output is correct
36 Correct 19 ms 600 KB Output is correct
37 Correct 39 ms 344 KB Output is correct
38 Correct 39 ms 348 KB Output is correct
39 Correct 27 ms 348 KB Output is correct
40 Correct 17 ms 344 KB Output is correct
41 Correct 20 ms 348 KB Output is correct
42 Correct 17 ms 348 KB Output is correct
43 Correct 19 ms 348 KB Output is correct
44 Correct 17 ms 344 KB Output is correct
45 Correct 17 ms 348 KB Output is correct
46 Correct 22 ms 544 KB Output is correct
47 Correct 18 ms 348 KB Output is correct
48 Correct 19 ms 532 KB Output is correct
49 Correct 20 ms 344 KB Output is correct
50 Correct 20 ms 464 KB Output is correct
51 Correct 15 ms 348 KB Output is correct
52 Correct 16 ms 528 KB Output is correct
53 Correct 20 ms 604 KB Output is correct
54 Correct 25 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 70 ms 23240 KB Output is correct
4 Correct 65 ms 23232 KB Output is correct
5 Correct 85 ms 23484 KB Output is correct
6 Correct 72 ms 21956 KB Output is correct
7 Correct 64 ms 22104 KB Output is correct
8 Correct 60 ms 20904 KB Output is correct
9 Correct 64 ms 21692 KB Output is correct
10 Correct 65 ms 23240 KB Output is correct
11 Correct 90 ms 21952 KB Output is correct
12 Correct 68 ms 23496 KB Output is correct
13 Correct 63 ms 20576 KB Output is correct
14 Correct 61 ms 21440 KB Output is correct
15 Correct 65 ms 22700 KB Output is correct
16 Correct 65 ms 23744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 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 1 ms 348 KB Output is correct
19 Correct 1 ms 452 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 70 ms 23240 KB Output is correct
30 Correct 65 ms 23232 KB Output is correct
31 Correct 85 ms 23484 KB Output is correct
32 Correct 72 ms 21956 KB Output is correct
33 Correct 64 ms 22104 KB Output is correct
34 Correct 60 ms 20904 KB Output is correct
35 Correct 64 ms 21692 KB Output is correct
36 Correct 65 ms 23240 KB Output is correct
37 Correct 90 ms 21952 KB Output is correct
38 Correct 68 ms 23496 KB Output is correct
39 Correct 63 ms 20576 KB Output is correct
40 Correct 61 ms 21440 KB Output is correct
41 Correct 65 ms 22700 KB Output is correct
42 Correct 65 ms 23744 KB Output is correct
43 Correct 567 ms 23604 KB Output is correct
44 Correct 1029 ms 24144 KB Output is correct
45 Correct 939 ms 24400 KB Output is correct
46 Correct 132 ms 22820 KB Output is correct
47 Correct 119 ms 23124 KB Output is correct
48 Correct 411 ms 22616 KB Output is correct
49 Correct 647 ms 24524 KB Output is correct
50 Correct 598 ms 22348 KB Output is correct
51 Correct 598 ms 23388 KB Output is correct
52 Correct 624 ms 24396 KB Output is correct
53 Correct 270 ms 21584 KB Output is correct
54 Correct 350 ms 22604 KB Output is correct
55 Correct 498 ms 23632 KB Output is correct
56 Correct 638 ms 24448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 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 1 ms 348 KB Output is correct
19 Correct 1 ms 452 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 19 ms 468 KB Output is correct
30 Correct 22 ms 348 KB Output is correct
31 Correct 20 ms 348 KB Output is correct
32 Correct 12 ms 532 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 18 ms 540 KB Output is correct
35 Correct 29 ms 540 KB Output is correct
36 Correct 19 ms 600 KB Output is correct
37 Correct 39 ms 344 KB Output is correct
38 Correct 39 ms 348 KB Output is correct
39 Correct 27 ms 348 KB Output is correct
40 Correct 17 ms 344 KB Output is correct
41 Correct 20 ms 348 KB Output is correct
42 Correct 17 ms 348 KB Output is correct
43 Correct 19 ms 348 KB Output is correct
44 Correct 17 ms 344 KB Output is correct
45 Correct 17 ms 348 KB Output is correct
46 Correct 22 ms 544 KB Output is correct
47 Correct 18 ms 348 KB Output is correct
48 Correct 19 ms 532 KB Output is correct
49 Correct 20 ms 344 KB Output is correct
50 Correct 20 ms 464 KB Output is correct
51 Correct 15 ms 348 KB Output is correct
52 Correct 16 ms 528 KB Output is correct
53 Correct 20 ms 604 KB Output is correct
54 Correct 25 ms 348 KB Output is correct
55 Correct 1969 ms 15416 KB Output is correct
56 Execution timed out 2065 ms 16980 KB Time limit exceeded
57 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 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 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 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 1 ms 348 KB Output is correct
19 Correct 1 ms 452 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 19 ms 468 KB Output is correct
30 Correct 22 ms 348 KB Output is correct
31 Correct 20 ms 348 KB Output is correct
32 Correct 12 ms 532 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 18 ms 540 KB Output is correct
35 Correct 29 ms 540 KB Output is correct
36 Correct 19 ms 600 KB Output is correct
37 Correct 39 ms 344 KB Output is correct
38 Correct 39 ms 348 KB Output is correct
39 Correct 27 ms 348 KB Output is correct
40 Correct 17 ms 344 KB Output is correct
41 Correct 20 ms 348 KB Output is correct
42 Correct 17 ms 348 KB Output is correct
43 Correct 19 ms 348 KB Output is correct
44 Correct 17 ms 344 KB Output is correct
45 Correct 17 ms 348 KB Output is correct
46 Correct 22 ms 544 KB Output is correct
47 Correct 18 ms 348 KB Output is correct
48 Correct 19 ms 532 KB Output is correct
49 Correct 20 ms 344 KB Output is correct
50 Correct 20 ms 464 KB Output is correct
51 Correct 15 ms 348 KB Output is correct
52 Correct 16 ms 528 KB Output is correct
53 Correct 20 ms 604 KB Output is correct
54 Correct 25 ms 348 KB Output is correct
55 Correct 70 ms 23240 KB Output is correct
56 Correct 65 ms 23232 KB Output is correct
57 Correct 85 ms 23484 KB Output is correct
58 Correct 72 ms 21956 KB Output is correct
59 Correct 64 ms 22104 KB Output is correct
60 Correct 60 ms 20904 KB Output is correct
61 Correct 64 ms 21692 KB Output is correct
62 Correct 65 ms 23240 KB Output is correct
63 Correct 90 ms 21952 KB Output is correct
64 Correct 68 ms 23496 KB Output is correct
65 Correct 63 ms 20576 KB Output is correct
66 Correct 61 ms 21440 KB Output is correct
67 Correct 65 ms 22700 KB Output is correct
68 Correct 65 ms 23744 KB Output is correct
69 Correct 567 ms 23604 KB Output is correct
70 Correct 1029 ms 24144 KB Output is correct
71 Correct 939 ms 24400 KB Output is correct
72 Correct 132 ms 22820 KB Output is correct
73 Correct 119 ms 23124 KB Output is correct
74 Correct 411 ms 22616 KB Output is correct
75 Correct 647 ms 24524 KB Output is correct
76 Correct 598 ms 22348 KB Output is correct
77 Correct 598 ms 23388 KB Output is correct
78 Correct 624 ms 24396 KB Output is correct
79 Correct 270 ms 21584 KB Output is correct
80 Correct 350 ms 22604 KB Output is correct
81 Correct 498 ms 23632 KB Output is correct
82 Correct 638 ms 24448 KB Output is correct
83 Correct 1969 ms 15416 KB Output is correct
84 Execution timed out 2065 ms 16980 KB Time limit exceeded
85 Halted 0 ms 0 KB -