답안 #1010834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010834 2024-06-29T12:15:18 Z VMaksimoski008 Joker (BOI20_joker) C++17
39 / 100
2000 ms 42656 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")

using pii = pair<int, int>;

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

    void init(int _n) {
        n = _n + 1;
        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;
        auto p2 = find(par[u].first);
        return { p2.first, p2.second ^ p };
    }

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

        st.push_back({ bi[pa.first], bi[pb.first] });
        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);

        st.push_back({ size[pa.first], size[pa.first] });
        st.push_back({ par[pa.first].first, par[pa.first].first });
        st.push_back({ par[pa.first].second, par[pa.first].second });

        size[pa.first] += size[pb.first];
        par[pb.first] = { pa.first, pa.second ^ pb.second ^ 1 };
        bi[pa.first] &= bi[pb.first];

        return 1;
    }

    void roll(int sz) {
        while(st.size() > sz) {
            st.back().first = st.back().second;
            st.pop_back();
        }
    }

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

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

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

    vector<array<int, 2> > edges(m);
    for(auto &[a, b] : edges) cin >> a >> b;

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

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

            cout << (!ans ? "YES" : "NO") << '\n';
        }
        
        return 0;
    }

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

    vector<bool> ans(q);
    for(int it=0; it<200; it++) {
        if(qus[it].empty()) continue;
        sort(qus[it].rbegin(), qus[it].rend());

        int p = 0, ok = 1;
        DSU dsu; dsu.init(n);
        for(int i=0; i<it; i++) {
            dsu.uni(edges[i][0], edges[i][1]);
            if(!dsu.getBi(edges[i][0])) ok = 0;
        }

        for(int i=m-1; i>=0&&ok; i--) {
            while(p < qus[it].size() && qus[it][p].first == i) {
                ans[qus[it][p].second] = ok;
                p++;
            }

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

    for(int i=0; i<q; i++)
        cout << (!ans[i] ? "YES" : "NO") << '\n';
    return 0;
}

Compilation message

Joker.cpp: In member function 'void DSU::roll(int)':
Joker.cpp:53: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]
   53 |         while(st.size() > sz) {
      |               ~~~~~~~~~~^~~~
Joker.cpp: In function 'int main()':
Joker.cpp:115:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |             while(p < qus[it].size() && qus[it][p].first == i) {
      |                   ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 348 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 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 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 476 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 348 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 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 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 476 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 72 ms 604 KB Output is correct
30 Correct 83 ms 704 KB Output is correct
31 Correct 66 ms 600 KB Output is correct
32 Correct 45 ms 344 KB Output is correct
33 Correct 28 ms 344 KB Output is correct
34 Correct 64 ms 708 KB Output is correct
35 Correct 144 ms 712 KB Output is correct
36 Correct 77 ms 604 KB Output is correct
37 Correct 182 ms 768 KB Output is correct
38 Correct 224 ms 776 KB Output is correct
39 Correct 122 ms 744 KB Output is correct
40 Correct 77 ms 604 KB Output is correct
41 Correct 61 ms 604 KB Output is correct
42 Correct 61 ms 612 KB Output is correct
43 Correct 54 ms 348 KB Output is correct
44 Correct 65 ms 600 KB Output is correct
45 Correct 73 ms 604 KB Output is correct
46 Correct 132 ms 712 KB Output is correct
47 Correct 55 ms 348 KB Output is correct
48 Correct 65 ms 612 KB Output is correct
49 Correct 75 ms 660 KB Output is correct
50 Correct 107 ms 712 KB Output is correct
51 Correct 52 ms 344 KB Output is correct
52 Correct 73 ms 604 KB Output is correct
53 Correct 70 ms 604 KB Output is correct
54 Correct 127 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 65 ms 17984 KB Output is correct
4 Correct 84 ms 27968 KB Output is correct
5 Correct 68 ms 14040 KB Output is correct
6 Correct 71 ms 18108 KB Output is correct
7 Correct 98 ms 19528 KB Output is correct
8 Correct 68 ms 17480 KB Output is correct
9 Correct 67 ms 19780 KB Output is correct
10 Correct 92 ms 19684 KB Output is correct
11 Correct 71 ms 18504 KB Output is correct
12 Correct 77 ms 20040 KB Output is correct
13 Correct 68 ms 12620 KB Output is correct
14 Correct 79 ms 17476 KB Output is correct
15 Correct 73 ms 18760 KB Output is correct
16 Correct 77 ms 19784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 348 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 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 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 476 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 65 ms 17984 KB Output is correct
30 Correct 84 ms 27968 KB Output is correct
31 Correct 68 ms 14040 KB Output is correct
32 Correct 71 ms 18108 KB Output is correct
33 Correct 98 ms 19528 KB Output is correct
34 Correct 68 ms 17480 KB Output is correct
35 Correct 67 ms 19780 KB Output is correct
36 Correct 92 ms 19684 KB Output is correct
37 Correct 71 ms 18504 KB Output is correct
38 Correct 77 ms 20040 KB Output is correct
39 Correct 68 ms 12620 KB Output is correct
40 Correct 79 ms 17476 KB Output is correct
41 Correct 73 ms 18760 KB Output is correct
42 Correct 77 ms 19784 KB Output is correct
43 Correct 1752 ms 25152 KB Output is correct
44 Execution timed out 2037 ms 42656 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 348 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 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 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 476 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 72 ms 604 KB Output is correct
30 Correct 83 ms 704 KB Output is correct
31 Correct 66 ms 600 KB Output is correct
32 Correct 45 ms 344 KB Output is correct
33 Correct 28 ms 344 KB Output is correct
34 Correct 64 ms 708 KB Output is correct
35 Correct 144 ms 712 KB Output is correct
36 Correct 77 ms 604 KB Output is correct
37 Correct 182 ms 768 KB Output is correct
38 Correct 224 ms 776 KB Output is correct
39 Correct 122 ms 744 KB Output is correct
40 Correct 77 ms 604 KB Output is correct
41 Correct 61 ms 604 KB Output is correct
42 Correct 61 ms 612 KB Output is correct
43 Correct 54 ms 348 KB Output is correct
44 Correct 65 ms 600 KB Output is correct
45 Correct 73 ms 604 KB Output is correct
46 Correct 132 ms 712 KB Output is correct
47 Correct 55 ms 348 KB Output is correct
48 Correct 65 ms 612 KB Output is correct
49 Correct 75 ms 660 KB Output is correct
50 Correct 107 ms 712 KB Output is correct
51 Correct 52 ms 344 KB Output is correct
52 Correct 73 ms 604 KB Output is correct
53 Correct 70 ms 604 KB Output is correct
54 Correct 127 ms 716 KB Output is correct
55 Incorrect 33 ms 16580 KB Output isn't correct
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 348 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 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 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 476 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 72 ms 604 KB Output is correct
30 Correct 83 ms 704 KB Output is correct
31 Correct 66 ms 600 KB Output is correct
32 Correct 45 ms 344 KB Output is correct
33 Correct 28 ms 344 KB Output is correct
34 Correct 64 ms 708 KB Output is correct
35 Correct 144 ms 712 KB Output is correct
36 Correct 77 ms 604 KB Output is correct
37 Correct 182 ms 768 KB Output is correct
38 Correct 224 ms 776 KB Output is correct
39 Correct 122 ms 744 KB Output is correct
40 Correct 77 ms 604 KB Output is correct
41 Correct 61 ms 604 KB Output is correct
42 Correct 61 ms 612 KB Output is correct
43 Correct 54 ms 348 KB Output is correct
44 Correct 65 ms 600 KB Output is correct
45 Correct 73 ms 604 KB Output is correct
46 Correct 132 ms 712 KB Output is correct
47 Correct 55 ms 348 KB Output is correct
48 Correct 65 ms 612 KB Output is correct
49 Correct 75 ms 660 KB Output is correct
50 Correct 107 ms 712 KB Output is correct
51 Correct 52 ms 344 KB Output is correct
52 Correct 73 ms 604 KB Output is correct
53 Correct 70 ms 604 KB Output is correct
54 Correct 127 ms 716 KB Output is correct
55 Correct 65 ms 17984 KB Output is correct
56 Correct 84 ms 27968 KB Output is correct
57 Correct 68 ms 14040 KB Output is correct
58 Correct 71 ms 18108 KB Output is correct
59 Correct 98 ms 19528 KB Output is correct
60 Correct 68 ms 17480 KB Output is correct
61 Correct 67 ms 19780 KB Output is correct
62 Correct 92 ms 19684 KB Output is correct
63 Correct 71 ms 18504 KB Output is correct
64 Correct 77 ms 20040 KB Output is correct
65 Correct 68 ms 12620 KB Output is correct
66 Correct 79 ms 17476 KB Output is correct
67 Correct 73 ms 18760 KB Output is correct
68 Correct 77 ms 19784 KB Output is correct
69 Correct 1752 ms 25152 KB Output is correct
70 Execution timed out 2037 ms 42656 KB Time limit exceeded
71 Halted 0 ms 0 KB -