답안 #1010826

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010826 2024-06-29T12:08:23 Z VMaksimoski008 Joker (BOI20_joker) C++17
49 / 100
1264 ms 16588 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;

    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;
        par[u] = find(par[u].first);
        par[u].second ^= p;
        return par[u];
    }

    bool uni(int a, int b) {
        pii 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]; }
};

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 function 'int main()':
Joker.cpp:101: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]
  101 |             while(p < qus[it].size() && qus[it][p].first == i) {
      |                   ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 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 0 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 1 ms 348 KB Output is correct
13 Correct 0 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 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 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 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 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 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 0 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 1 ms 348 KB Output is correct
13 Correct 0 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 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 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 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 20 ms 348 KB Output is correct
30 Correct 22 ms 348 KB Output is correct
31 Correct 21 ms 344 KB Output is correct
32 Correct 12 ms 520 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 18 ms 348 KB Output is correct
35 Correct 25 ms 348 KB Output is correct
36 Correct 20 ms 344 KB Output is correct
37 Correct 62 ms 540 KB Output is correct
38 Correct 39 ms 348 KB Output is correct
39 Correct 25 ms 468 KB Output is correct
40 Correct 15 ms 528 KB Output is correct
41 Correct 17 ms 532 KB Output is correct
42 Correct 17 ms 348 KB Output is correct
43 Correct 22 ms 348 KB Output is correct
44 Correct 19 ms 348 KB Output is correct
45 Correct 20 ms 348 KB Output is correct
46 Correct 23 ms 348 KB Output is correct
47 Correct 28 ms 344 KB Output is correct
48 Correct 25 ms 348 KB Output is correct
49 Correct 20 ms 348 KB Output is correct
50 Correct 21 ms 544 KB Output is correct
51 Correct 15 ms 348 KB Output is correct
52 Correct 19 ms 348 KB Output is correct
53 Correct 20 ms 532 KB Output is correct
54 Correct 31 ms 548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 87 ms 14288 KB Output is correct
4 Correct 69 ms 14932 KB Output is correct
5 Correct 67 ms 15308 KB Output is correct
6 Correct 68 ms 14284 KB Output is correct
7 Correct 85 ms 14420 KB Output is correct
8 Correct 63 ms 13264 KB Output is correct
9 Correct 64 ms 14196 KB Output is correct
10 Correct 72 ms 14796 KB Output is correct
11 Correct 67 ms 14304 KB Output is correct
12 Correct 74 ms 15040 KB Output is correct
13 Correct 70 ms 12996 KB Output is correct
14 Correct 74 ms 13772 KB Output is correct
15 Correct 75 ms 14392 KB Output is correct
16 Correct 70 ms 15348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 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 0 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 1 ms 348 KB Output is correct
13 Correct 0 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 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 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 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 87 ms 14288 KB Output is correct
30 Correct 69 ms 14932 KB Output is correct
31 Correct 67 ms 15308 KB Output is correct
32 Correct 68 ms 14284 KB Output is correct
33 Correct 85 ms 14420 KB Output is correct
34 Correct 63 ms 13264 KB Output is correct
35 Correct 64 ms 14196 KB Output is correct
36 Correct 72 ms 14796 KB Output is correct
37 Correct 67 ms 14304 KB Output is correct
38 Correct 74 ms 15040 KB Output is correct
39 Correct 70 ms 12996 KB Output is correct
40 Correct 74 ms 13772 KB Output is correct
41 Correct 75 ms 14392 KB Output is correct
42 Correct 70 ms 15348 KB Output is correct
43 Correct 588 ms 14840 KB Output is correct
44 Correct 1264 ms 16144 KB Output is correct
45 Correct 1159 ms 16588 KB Output is correct
46 Correct 234 ms 14792 KB Output is correct
47 Correct 225 ms 15052 KB Output is correct
48 Correct 510 ms 14504 KB Output is correct
49 Correct 906 ms 16188 KB Output is correct
50 Correct 681 ms 14456 KB Output is correct
51 Correct 735 ms 15620 KB Output is correct
52 Correct 742 ms 16540 KB Output is correct
53 Correct 273 ms 13676 KB Output is correct
54 Correct 495 ms 14512 KB Output is correct
55 Correct 639 ms 15648 KB Output is correct
56 Correct 815 ms 16556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 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 0 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 1 ms 348 KB Output is correct
13 Correct 0 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 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 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 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 20 ms 348 KB Output is correct
30 Correct 22 ms 348 KB Output is correct
31 Correct 21 ms 344 KB Output is correct
32 Correct 12 ms 520 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 18 ms 348 KB Output is correct
35 Correct 25 ms 348 KB Output is correct
36 Correct 20 ms 344 KB Output is correct
37 Correct 62 ms 540 KB Output is correct
38 Correct 39 ms 348 KB Output is correct
39 Correct 25 ms 468 KB Output is correct
40 Correct 15 ms 528 KB Output is correct
41 Correct 17 ms 532 KB Output is correct
42 Correct 17 ms 348 KB Output is correct
43 Correct 22 ms 348 KB Output is correct
44 Correct 19 ms 348 KB Output is correct
45 Correct 20 ms 348 KB Output is correct
46 Correct 23 ms 348 KB Output is correct
47 Correct 28 ms 344 KB Output is correct
48 Correct 25 ms 348 KB Output is correct
49 Correct 20 ms 348 KB Output is correct
50 Correct 21 ms 544 KB Output is correct
51 Correct 15 ms 348 KB Output is correct
52 Correct 19 ms 348 KB Output is correct
53 Correct 20 ms 532 KB Output is correct
54 Correct 31 ms 548 KB Output is correct
55 Incorrect 22 ms 10588 KB Output isn't correct
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 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 0 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 1 ms 348 KB Output is correct
13 Correct 0 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 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 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 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 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 20 ms 348 KB Output is correct
30 Correct 22 ms 348 KB Output is correct
31 Correct 21 ms 344 KB Output is correct
32 Correct 12 ms 520 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 18 ms 348 KB Output is correct
35 Correct 25 ms 348 KB Output is correct
36 Correct 20 ms 344 KB Output is correct
37 Correct 62 ms 540 KB Output is correct
38 Correct 39 ms 348 KB Output is correct
39 Correct 25 ms 468 KB Output is correct
40 Correct 15 ms 528 KB Output is correct
41 Correct 17 ms 532 KB Output is correct
42 Correct 17 ms 348 KB Output is correct
43 Correct 22 ms 348 KB Output is correct
44 Correct 19 ms 348 KB Output is correct
45 Correct 20 ms 348 KB Output is correct
46 Correct 23 ms 348 KB Output is correct
47 Correct 28 ms 344 KB Output is correct
48 Correct 25 ms 348 KB Output is correct
49 Correct 20 ms 348 KB Output is correct
50 Correct 21 ms 544 KB Output is correct
51 Correct 15 ms 348 KB Output is correct
52 Correct 19 ms 348 KB Output is correct
53 Correct 20 ms 532 KB Output is correct
54 Correct 31 ms 548 KB Output is correct
55 Correct 87 ms 14288 KB Output is correct
56 Correct 69 ms 14932 KB Output is correct
57 Correct 67 ms 15308 KB Output is correct
58 Correct 68 ms 14284 KB Output is correct
59 Correct 85 ms 14420 KB Output is correct
60 Correct 63 ms 13264 KB Output is correct
61 Correct 64 ms 14196 KB Output is correct
62 Correct 72 ms 14796 KB Output is correct
63 Correct 67 ms 14304 KB Output is correct
64 Correct 74 ms 15040 KB Output is correct
65 Correct 70 ms 12996 KB Output is correct
66 Correct 74 ms 13772 KB Output is correct
67 Correct 75 ms 14392 KB Output is correct
68 Correct 70 ms 15348 KB Output is correct
69 Correct 588 ms 14840 KB Output is correct
70 Correct 1264 ms 16144 KB Output is correct
71 Correct 1159 ms 16588 KB Output is correct
72 Correct 234 ms 14792 KB Output is correct
73 Correct 225 ms 15052 KB Output is correct
74 Correct 510 ms 14504 KB Output is correct
75 Correct 906 ms 16188 KB Output is correct
76 Correct 681 ms 14456 KB Output is correct
77 Correct 735 ms 15620 KB Output is correct
78 Correct 742 ms 16540 KB Output is correct
79 Correct 273 ms 13676 KB Output is correct
80 Correct 495 ms 14512 KB Output is correct
81 Correct 639 ms 15648 KB Output is correct
82 Correct 815 ms 16556 KB Output is correct
83 Incorrect 22 ms 10588 KB Output isn't correct
84 Halted 0 ms 0 KB -