답안 #726706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726706 2023-04-19T09:20:52 Z Johann Joker (BOI20_joker) C++14
49 / 100
2000 ms 28660 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;
    vi cxorp; // xor with color of parent?
    bool oddCycle;
    void init()
    {
        oddCycle = false, arr.resize(N);
        iota(all(arr), 0);
        color.assign(N, 0), cxorp.assign(N, 0);
    }
    int find(int i)
    {
        if (arr[i] == i)
            return i;
        int p = arr[i];
        arr[i] = find(p);
        color[i] = color[p] ^ cxorp[i];
        cxorp[i] = cxorp[i] ^ cxorp[p];
        return arr[i];
    }
    bool join(int a, int b)
    {
        int pa = find(a), pb = find(b); // get color to newest
        bool sameColor = (color[a] == color[b]);
        if (pa == pb)
        {
            oddCycle = oddCycle || sameColor;
            return sameColor;
        }
        arr[pb] = pa;
        if (sameColor)
        {
            cxorp[pb] = 1;
            color[pb] = color[pa] ^ cxorp[pb];
        }
        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 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 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 316 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 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 316 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 17 ms 452 KB Output is correct
30 Correct 33 ms 576 KB Output is correct
31 Correct 38 ms 568 KB Output is correct
32 Correct 36 ms 468 KB Output is correct
33 Correct 35 ms 532 KB Output is correct
34 Correct 35 ms 716 KB Output is correct
35 Correct 38 ms 596 KB Output is correct
36 Correct 31 ms 544 KB Output is correct
37 Correct 43 ms 604 KB Output is correct
38 Correct 53 ms 600 KB Output is correct
39 Correct 36 ms 588 KB Output is correct
40 Correct 27 ms 468 KB Output is correct
41 Correct 30 ms 548 KB Output is correct
42 Correct 28 ms 552 KB Output is correct
43 Correct 34 ms 468 KB Output is correct
44 Correct 36 ms 460 KB Output is correct
45 Correct 35 ms 592 KB Output is correct
46 Correct 38 ms 596 KB Output is correct
47 Correct 33 ms 528 KB Output is correct
48 Correct 37 ms 544 KB Output is correct
49 Correct 34 ms 580 KB Output is correct
50 Correct 40 ms 596 KB Output is correct
51 Correct 38 ms 468 KB Output is correct
52 Correct 37 ms 468 KB Output is correct
53 Correct 43 ms 576 KB Output is correct
54 Correct 44 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 114 ms 19124 KB Output is correct
4 Correct 132 ms 24640 KB Output is correct
5 Correct 129 ms 23564 KB Output is correct
6 Correct 132 ms 20300 KB Output is correct
7 Correct 104 ms 19920 KB Output is correct
8 Correct 120 ms 18036 KB Output is correct
9 Correct 138 ms 19900 KB Output is correct
10 Correct 151 ms 24240 KB Output is correct
11 Correct 119 ms 19908 KB Output is correct
12 Correct 131 ms 23732 KB Output is correct
13 Correct 108 ms 16136 KB Output is correct
14 Correct 121 ms 17860 KB Output is correct
15 Correct 144 ms 21572 KB Output is correct
16 Correct 164 ms 24088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 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 316 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 114 ms 19124 KB Output is correct
30 Correct 132 ms 24640 KB Output is correct
31 Correct 129 ms 23564 KB Output is correct
32 Correct 132 ms 20300 KB Output is correct
33 Correct 104 ms 19920 KB Output is correct
34 Correct 120 ms 18036 KB Output is correct
35 Correct 138 ms 19900 KB Output is correct
36 Correct 151 ms 24240 KB Output is correct
37 Correct 119 ms 19908 KB Output is correct
38 Correct 131 ms 23732 KB Output is correct
39 Correct 108 ms 16136 KB Output is correct
40 Correct 121 ms 17860 KB Output is correct
41 Correct 144 ms 21572 KB Output is correct
42 Correct 164 ms 24088 KB Output is correct
43 Correct 635 ms 19484 KB Output is correct
44 Correct 1545 ms 28104 KB Output is correct
45 Correct 1342 ms 28660 KB Output is correct
46 Correct 196 ms 24652 KB Output is correct
47 Correct 227 ms 24516 KB Output is correct
48 Correct 700 ms 23912 KB Output is correct
49 Correct 1290 ms 28512 KB Output is correct
50 Correct 1180 ms 23048 KB Output is correct
51 Correct 1150 ms 26152 KB Output is correct
52 Correct 1035 ms 28572 KB Output is correct
53 Correct 771 ms 20544 KB Output is correct
54 Correct 726 ms 23380 KB Output is correct
55 Correct 1044 ms 26272 KB Output is correct
56 Correct 1277 ms 28604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 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 316 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 17 ms 452 KB Output is correct
30 Correct 33 ms 576 KB Output is correct
31 Correct 38 ms 568 KB Output is correct
32 Correct 36 ms 468 KB Output is correct
33 Correct 35 ms 532 KB Output is correct
34 Correct 35 ms 716 KB Output is correct
35 Correct 38 ms 596 KB Output is correct
36 Correct 31 ms 544 KB Output is correct
37 Correct 43 ms 604 KB Output is correct
38 Correct 53 ms 600 KB Output is correct
39 Correct 36 ms 588 KB Output is correct
40 Correct 27 ms 468 KB Output is correct
41 Correct 30 ms 548 KB Output is correct
42 Correct 28 ms 552 KB Output is correct
43 Correct 34 ms 468 KB Output is correct
44 Correct 36 ms 460 KB Output is correct
45 Correct 35 ms 592 KB Output is correct
46 Correct 38 ms 596 KB Output is correct
47 Correct 33 ms 528 KB Output is correct
48 Correct 37 ms 544 KB Output is correct
49 Correct 34 ms 580 KB Output is correct
50 Correct 40 ms 596 KB Output is correct
51 Correct 38 ms 468 KB Output is correct
52 Correct 37 ms 468 KB Output is correct
53 Correct 43 ms 576 KB Output is correct
54 Correct 44 ms 596 KB Output is correct
55 Execution timed out 2053 ms 15644 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 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 316 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 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 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 17 ms 452 KB Output is correct
30 Correct 33 ms 576 KB Output is correct
31 Correct 38 ms 568 KB Output is correct
32 Correct 36 ms 468 KB Output is correct
33 Correct 35 ms 532 KB Output is correct
34 Correct 35 ms 716 KB Output is correct
35 Correct 38 ms 596 KB Output is correct
36 Correct 31 ms 544 KB Output is correct
37 Correct 43 ms 604 KB Output is correct
38 Correct 53 ms 600 KB Output is correct
39 Correct 36 ms 588 KB Output is correct
40 Correct 27 ms 468 KB Output is correct
41 Correct 30 ms 548 KB Output is correct
42 Correct 28 ms 552 KB Output is correct
43 Correct 34 ms 468 KB Output is correct
44 Correct 36 ms 460 KB Output is correct
45 Correct 35 ms 592 KB Output is correct
46 Correct 38 ms 596 KB Output is correct
47 Correct 33 ms 528 KB Output is correct
48 Correct 37 ms 544 KB Output is correct
49 Correct 34 ms 580 KB Output is correct
50 Correct 40 ms 596 KB Output is correct
51 Correct 38 ms 468 KB Output is correct
52 Correct 37 ms 468 KB Output is correct
53 Correct 43 ms 576 KB Output is correct
54 Correct 44 ms 596 KB Output is correct
55 Correct 114 ms 19124 KB Output is correct
56 Correct 132 ms 24640 KB Output is correct
57 Correct 129 ms 23564 KB Output is correct
58 Correct 132 ms 20300 KB Output is correct
59 Correct 104 ms 19920 KB Output is correct
60 Correct 120 ms 18036 KB Output is correct
61 Correct 138 ms 19900 KB Output is correct
62 Correct 151 ms 24240 KB Output is correct
63 Correct 119 ms 19908 KB Output is correct
64 Correct 131 ms 23732 KB Output is correct
65 Correct 108 ms 16136 KB Output is correct
66 Correct 121 ms 17860 KB Output is correct
67 Correct 144 ms 21572 KB Output is correct
68 Correct 164 ms 24088 KB Output is correct
69 Correct 635 ms 19484 KB Output is correct
70 Correct 1545 ms 28104 KB Output is correct
71 Correct 1342 ms 28660 KB Output is correct
72 Correct 196 ms 24652 KB Output is correct
73 Correct 227 ms 24516 KB Output is correct
74 Correct 700 ms 23912 KB Output is correct
75 Correct 1290 ms 28512 KB Output is correct
76 Correct 1180 ms 23048 KB Output is correct
77 Correct 1150 ms 26152 KB Output is correct
78 Correct 1035 ms 28572 KB Output is correct
79 Correct 771 ms 20544 KB Output is correct
80 Correct 726 ms 23380 KB Output is correct
81 Correct 1044 ms 26272 KB Output is correct
82 Correct 1277 ms 28604 KB Output is correct
83 Execution timed out 2053 ms 15644 KB Time limit exceeded
84 Halted 0 ms 0 KB -