답안 #726677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726677 2023-04-19T09:04:52 Z Johann Joker (BOI20_joker) C++14
39 / 100
2000 ms 39224 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

int N, M, Q;
vvpii adj;
vpii E;

struct DSU
{
    vi arr;
    vi color;
    vvi contains;
    bool oddCycle;
    void init()
    {
        oddCycle = false;
        arr.resize(N);
        iota(all(arr), 0);
        color.assign(N, 0);
        contains.resize(N);
        for (int i = 0; i < N; ++i)
            contains[i].clear(), contains[i].push_back(i);
    }
    int find(int i)
    {
        return arr[i] = (arr[i] == i) ? i : find(arr[i]);
    }
    bool join(int a, int b)
    {
        bool sameColor = (color[a] == color[b]);
        a = find(a), b = find(b);
        if (a == b)
        {
            oddCycle = oddCycle || sameColor;
            return sameColor;
        }
        if (sz(contains[a]) < sz(contains[b]))
            swap(a, b);
        arr[b] = a;
        while (!contains[b].empty())
        {
            int u = contains[b].back();
            contains[b].pop_back();
            contains[a].push_back(u);
            if (sameColor)
                color[u] = !color[u];
        }
        return false;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> M >> Q;
    adj.resize(N);
    E.resize(M);
    for (int i = 0, a, b; i < M; ++i)
    {
        cin >> a >> b;
        --a, --b;
        adj[a].push_back({b, i}), adj[b].push_back({a, i});
        E[i] = {min(a, b), max(a, b)};
    }

    vvpii Queries(M + 1);
    vi ans(Q);
    for (int i = 0, l, r; i < Q; ++i)
    {
        cin >> l >> r;
        --l, --r; // [l, r] inclusive is blocked
        l = min(M, l), r = min(M, r);
        Queries[l].push_back({r, i});
    }

    DSU dsu;
    for (int l = 0; l < sz(Queries); ++l)
    {
        if (Queries[l].empty())
            continue;
        dsu.init();

        for (int i = 0; i < l; ++i)
            dsu.join(E[i].first, E[i].second);
        int r = M - 1;
        while (!dsu.oddCycle && r >= l)
        {
            dsu.join(E[r].first, E[r].second);
            --r;
        }
        for (pii q : Queries[l])
            ans[q.second] = (q.first <= r);
    }

    for (int a : ans)
        if (a)
            cout << "YES\n";
        else
            cout << "NO\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 41 ms 636 KB Output is correct
30 Correct 69 ms 716 KB Output is correct
31 Correct 70 ms 696 KB Output is correct
32 Correct 50 ms 632 KB Output is correct
33 Correct 39 ms 468 KB Output is correct
34 Correct 75 ms 716 KB Output is correct
35 Correct 81 ms 724 KB Output is correct
36 Correct 47 ms 600 KB Output is correct
37 Correct 84 ms 724 KB Output is correct
38 Correct 101 ms 828 KB Output is correct
39 Correct 55 ms 688 KB Output is correct
40 Correct 49 ms 624 KB Output is correct
41 Correct 47 ms 596 KB Output is correct
42 Correct 46 ms 632 KB Output is correct
43 Correct 40 ms 588 KB Output is correct
44 Correct 52 ms 704 KB Output is correct
45 Correct 64 ms 700 KB Output is correct
46 Correct 79 ms 744 KB Output is correct
47 Correct 41 ms 596 KB Output is correct
48 Correct 48 ms 632 KB Output is correct
49 Correct 60 ms 596 KB Output is correct
50 Correct 75 ms 724 KB Output is correct
51 Correct 41 ms 584 KB Output is correct
52 Correct 49 ms 644 KB Output is correct
53 Correct 65 ms 692 KB Output is correct
54 Correct 81 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 131 ms 25816 KB Output is correct
4 Correct 192 ms 37056 KB Output is correct
5 Correct 144 ms 33204 KB Output is correct
6 Correct 137 ms 26280 KB Output is correct
7 Correct 141 ms 27228 KB Output is correct
8 Correct 124 ms 22200 KB Output is correct
9 Correct 137 ms 26660 KB Output is correct
10 Correct 188 ms 35820 KB Output is correct
11 Correct 132 ms 25824 KB Output is correct
12 Correct 147 ms 33468 KB Output is correct
13 Correct 102 ms 17844 KB Output is correct
14 Correct 125 ms 22048 KB Output is correct
15 Correct 163 ms 30524 KB Output is correct
16 Correct 222 ms 35656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 131 ms 25816 KB Output is correct
30 Correct 192 ms 37056 KB Output is correct
31 Correct 144 ms 33204 KB Output is correct
32 Correct 137 ms 26280 KB Output is correct
33 Correct 141 ms 27228 KB Output is correct
34 Correct 124 ms 22200 KB Output is correct
35 Correct 137 ms 26660 KB Output is correct
36 Correct 188 ms 35820 KB Output is correct
37 Correct 132 ms 25824 KB Output is correct
38 Correct 147 ms 33468 KB Output is correct
39 Correct 102 ms 17844 KB Output is correct
40 Correct 125 ms 22048 KB Output is correct
41 Correct 163 ms 30524 KB Output is correct
42 Correct 222 ms 35656 KB Output is correct
43 Correct 1750 ms 25348 KB Output is correct
44 Execution timed out 2037 ms 39224 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 41 ms 636 KB Output is correct
30 Correct 69 ms 716 KB Output is correct
31 Correct 70 ms 696 KB Output is correct
32 Correct 50 ms 632 KB Output is correct
33 Correct 39 ms 468 KB Output is correct
34 Correct 75 ms 716 KB Output is correct
35 Correct 81 ms 724 KB Output is correct
36 Correct 47 ms 600 KB Output is correct
37 Correct 84 ms 724 KB Output is correct
38 Correct 101 ms 828 KB Output is correct
39 Correct 55 ms 688 KB Output is correct
40 Correct 49 ms 624 KB Output is correct
41 Correct 47 ms 596 KB Output is correct
42 Correct 46 ms 632 KB Output is correct
43 Correct 40 ms 588 KB Output is correct
44 Correct 52 ms 704 KB Output is correct
45 Correct 64 ms 700 KB Output is correct
46 Correct 79 ms 744 KB Output is correct
47 Correct 41 ms 596 KB Output is correct
48 Correct 48 ms 632 KB Output is correct
49 Correct 60 ms 596 KB Output is correct
50 Correct 75 ms 724 KB Output is correct
51 Correct 41 ms 584 KB Output is correct
52 Correct 49 ms 644 KB Output is correct
53 Correct 65 ms 692 KB Output is correct
54 Correct 81 ms 752 KB Output is correct
55 Execution timed out 2058 ms 21692 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 2 ms 324 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 41 ms 636 KB Output is correct
30 Correct 69 ms 716 KB Output is correct
31 Correct 70 ms 696 KB Output is correct
32 Correct 50 ms 632 KB Output is correct
33 Correct 39 ms 468 KB Output is correct
34 Correct 75 ms 716 KB Output is correct
35 Correct 81 ms 724 KB Output is correct
36 Correct 47 ms 600 KB Output is correct
37 Correct 84 ms 724 KB Output is correct
38 Correct 101 ms 828 KB Output is correct
39 Correct 55 ms 688 KB Output is correct
40 Correct 49 ms 624 KB Output is correct
41 Correct 47 ms 596 KB Output is correct
42 Correct 46 ms 632 KB Output is correct
43 Correct 40 ms 588 KB Output is correct
44 Correct 52 ms 704 KB Output is correct
45 Correct 64 ms 700 KB Output is correct
46 Correct 79 ms 744 KB Output is correct
47 Correct 41 ms 596 KB Output is correct
48 Correct 48 ms 632 KB Output is correct
49 Correct 60 ms 596 KB Output is correct
50 Correct 75 ms 724 KB Output is correct
51 Correct 41 ms 584 KB Output is correct
52 Correct 49 ms 644 KB Output is correct
53 Correct 65 ms 692 KB Output is correct
54 Correct 81 ms 752 KB Output is correct
55 Correct 131 ms 25816 KB Output is correct
56 Correct 192 ms 37056 KB Output is correct
57 Correct 144 ms 33204 KB Output is correct
58 Correct 137 ms 26280 KB Output is correct
59 Correct 141 ms 27228 KB Output is correct
60 Correct 124 ms 22200 KB Output is correct
61 Correct 137 ms 26660 KB Output is correct
62 Correct 188 ms 35820 KB Output is correct
63 Correct 132 ms 25824 KB Output is correct
64 Correct 147 ms 33468 KB Output is correct
65 Correct 102 ms 17844 KB Output is correct
66 Correct 125 ms 22048 KB Output is correct
67 Correct 163 ms 30524 KB Output is correct
68 Correct 222 ms 35656 KB Output is correct
69 Correct 1750 ms 25348 KB Output is correct
70 Execution timed out 2037 ms 39224 KB Time limit exceeded
71 Halted 0 ms 0 KB -