답안 #414771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414771 2021-05-31T07:34:54 Z two_sides Joker (BOI20_joker) C++17
100 / 100
656 ms 20004 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second

struct DSU {
    vector <int> par, siz;
    vector <int> tim, ver;

    DSU(int N): par(N + 5, 0), siz(N + 5, 1) {}

    int root(int u) {
        while (par[u]) u = par[u];
        return u;
    }

    void join(int u, int v) {
        u = root(u); v = root(v);
        if (u == v) return;
        if (siz[u] < siz[v]) swap(u, v);
        par[v] = u; siz[u] += siz[v]; 
        ver.push_back(v);
    } 

    void push(int u, int v) {
        tim.push_back(ver.size());
        join(2 * u - 1, 2 * v);
        join(2 * u, 2 * v - 1);
    }

    void pop() {
        while (ver.size() > tim.back()) {
            int v = ver.back();
            ver.pop_back();
            siz[par[v]] -= siz[v];
            par[v] = 0;
        }
        tim.pop_back();
    }

    bool check(int u, int v) {
        return root(2 * u) == root(2 * v);
    }
};

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int N, M, Q;
    cin >> N >> M >> Q;
    DSU dsu(N * 2);
    vector <pair <int, int>> E(M);
    for (int i = 0; i < M; i++)
        cin >> E[i].fi >> E[i].se;
    vector <pair <int, int>> buc, tmp[2];
    auto pop = [&]() {
        if (buc.back().se) {
            while (buc.size()) {
                auto p = buc.back();
                buc.pop_back(); dsu.pop();
                tmp[p.se].push_back(p);
                if (tmp[0].size() == tmp[1].size())
                    break;
            }
            if (tmp[0].empty()) {
                for (auto &p : tmp[1]) {
                    dsu.push(E[p.fi].fi, E[p.fi].se);
                    p.se = 0;
                }
                swap(tmp[1], buc);
            } else {
                while (tmp[1].size()) {
                    auto p = tmp[1].back();
                    tmp[1].pop_back();
                    buc.push_back(p);
                    dsu.push(E[p.fi].fi, E[p.fi].se);
                }
                while (tmp[0].size()) {
                    auto p = tmp[0].back();
                    tmp[0].pop_back();
                    buc.push_back(p);
                    dsu.push(E[p.fi].fi, E[p.fi].se);
                }
            }
        }
        dsu.pop(); buc.pop_back();
    };
    auto push = [&](int i) {
        buc.emplace_back(i, 1);
        dsu.push(E[i].fi, E[i].se);
    };
    vector <int> lim(2 * M);
    for (int i = 0, j = 0; i < 2 * M; i++) {
        int u, v; tie(u, v) = E[i % M];
        while (dsu.check(u, v)) {
            pop(); j++;
        }
        lim[i] = j; push(i % M);
    }
    while (Q--) {
        int l, r; cin >> l >> r;
        if (lim[l + M - 2] <= r)
            cout << "NO\n";
        else cout << "YES\n";
    }
}

Compilation message

Joker.cpp: In member function 'void DSU::pop()':
Joker.cpp:34:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   34 |         while (ver.size() > tim.back()) {
      |                ~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 4 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 3 ms 456 KB Output is correct
35 Correct 3 ms 460 KB Output is correct
36 Correct 5 ms 440 KB Output is correct
37 Correct 3 ms 460 KB Output is correct
38 Correct 2 ms 460 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 3 ms 332 KB Output is correct
41 Correct 3 ms 324 KB Output is correct
42 Correct 4 ms 332 KB Output is correct
43 Correct 3 ms 324 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 4 ms 448 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 3 ms 332 KB Output is correct
48 Correct 4 ms 332 KB Output is correct
49 Correct 4 ms 460 KB Output is correct
50 Correct 4 ms 460 KB Output is correct
51 Correct 3 ms 332 KB Output is correct
52 Correct 4 ms 332 KB Output is correct
53 Correct 4 ms 460 KB Output is correct
54 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 622 ms 10840 KB Output is correct
4 Correct 113 ms 19044 KB Output is correct
5 Correct 263 ms 18092 KB Output is correct
6 Correct 310 ms 13360 KB Output is correct
7 Correct 356 ms 13412 KB Output is correct
8 Correct 291 ms 11940 KB Output is correct
9 Correct 362 ms 12668 KB Output is correct
10 Correct 418 ms 14836 KB Output is correct
11 Correct 440 ms 13276 KB Output is correct
12 Correct 367 ms 15020 KB Output is correct
13 Correct 191 ms 11392 KB Output is correct
14 Correct 292 ms 12516 KB Output is correct
15 Correct 411 ms 13996 KB Output is correct
16 Correct 412 ms 15200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 622 ms 10840 KB Output is correct
30 Correct 113 ms 19044 KB Output is correct
31 Correct 263 ms 18092 KB Output is correct
32 Correct 310 ms 13360 KB Output is correct
33 Correct 356 ms 13412 KB Output is correct
34 Correct 291 ms 11940 KB Output is correct
35 Correct 362 ms 12668 KB Output is correct
36 Correct 418 ms 14836 KB Output is correct
37 Correct 440 ms 13276 KB Output is correct
38 Correct 367 ms 15020 KB Output is correct
39 Correct 191 ms 11392 KB Output is correct
40 Correct 292 ms 12516 KB Output is correct
41 Correct 411 ms 13996 KB Output is correct
42 Correct 412 ms 15200 KB Output is correct
43 Correct 624 ms 13644 KB Output is correct
44 Correct 116 ms 19552 KB Output is correct
45 Correct 217 ms 19056 KB Output is correct
46 Correct 295 ms 13872 KB Output is correct
47 Correct 446 ms 13760 KB Output is correct
48 Correct 402 ms 13272 KB Output is correct
49 Correct 408 ms 15276 KB Output is correct
50 Correct 460 ms 13100 KB Output is correct
51 Correct 388 ms 14360 KB Output is correct
52 Correct 408 ms 15936 KB Output is correct
53 Correct 216 ms 11700 KB Output is correct
54 Correct 358 ms 13120 KB Output is correct
55 Correct 424 ms 14404 KB Output is correct
56 Correct 388 ms 15532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 4 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 3 ms 456 KB Output is correct
35 Correct 3 ms 460 KB Output is correct
36 Correct 5 ms 440 KB Output is correct
37 Correct 3 ms 460 KB Output is correct
38 Correct 2 ms 460 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 3 ms 332 KB Output is correct
41 Correct 3 ms 324 KB Output is correct
42 Correct 4 ms 332 KB Output is correct
43 Correct 3 ms 324 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 4 ms 448 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 3 ms 332 KB Output is correct
48 Correct 4 ms 332 KB Output is correct
49 Correct 4 ms 460 KB Output is correct
50 Correct 4 ms 460 KB Output is correct
51 Correct 3 ms 332 KB Output is correct
52 Correct 4 ms 332 KB Output is correct
53 Correct 4 ms 460 KB Output is correct
54 Correct 4 ms 468 KB Output is correct
55 Correct 581 ms 11120 KB Output is correct
56 Correct 82 ms 17372 KB Output is correct
57 Correct 199 ms 15660 KB Output is correct
58 Correct 301 ms 11116 KB Output is correct
59 Correct 332 ms 10952 KB Output is correct
60 Correct 459 ms 12204 KB Output is correct
61 Correct 417 ms 11084 KB Output is correct
62 Correct 358 ms 12716 KB Output is correct
63 Correct 184 ms 9656 KB Output is correct
64 Correct 428 ms 11528 KB Output is correct
65 Correct 373 ms 12568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 4 ms 332 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 3 ms 456 KB Output is correct
35 Correct 3 ms 460 KB Output is correct
36 Correct 5 ms 440 KB Output is correct
37 Correct 3 ms 460 KB Output is correct
38 Correct 2 ms 460 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 3 ms 332 KB Output is correct
41 Correct 3 ms 324 KB Output is correct
42 Correct 4 ms 332 KB Output is correct
43 Correct 3 ms 324 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 4 ms 448 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 3 ms 332 KB Output is correct
48 Correct 4 ms 332 KB Output is correct
49 Correct 4 ms 460 KB Output is correct
50 Correct 4 ms 460 KB Output is correct
51 Correct 3 ms 332 KB Output is correct
52 Correct 4 ms 332 KB Output is correct
53 Correct 4 ms 460 KB Output is correct
54 Correct 4 ms 468 KB Output is correct
55 Correct 622 ms 10840 KB Output is correct
56 Correct 113 ms 19044 KB Output is correct
57 Correct 263 ms 18092 KB Output is correct
58 Correct 310 ms 13360 KB Output is correct
59 Correct 356 ms 13412 KB Output is correct
60 Correct 291 ms 11940 KB Output is correct
61 Correct 362 ms 12668 KB Output is correct
62 Correct 418 ms 14836 KB Output is correct
63 Correct 440 ms 13276 KB Output is correct
64 Correct 367 ms 15020 KB Output is correct
65 Correct 191 ms 11392 KB Output is correct
66 Correct 292 ms 12516 KB Output is correct
67 Correct 411 ms 13996 KB Output is correct
68 Correct 412 ms 15200 KB Output is correct
69 Correct 624 ms 13644 KB Output is correct
70 Correct 116 ms 19552 KB Output is correct
71 Correct 217 ms 19056 KB Output is correct
72 Correct 295 ms 13872 KB Output is correct
73 Correct 446 ms 13760 KB Output is correct
74 Correct 402 ms 13272 KB Output is correct
75 Correct 408 ms 15276 KB Output is correct
76 Correct 460 ms 13100 KB Output is correct
77 Correct 388 ms 14360 KB Output is correct
78 Correct 408 ms 15936 KB Output is correct
79 Correct 216 ms 11700 KB Output is correct
80 Correct 358 ms 13120 KB Output is correct
81 Correct 424 ms 14404 KB Output is correct
82 Correct 388 ms 15532 KB Output is correct
83 Correct 581 ms 11120 KB Output is correct
84 Correct 82 ms 17372 KB Output is correct
85 Correct 199 ms 15660 KB Output is correct
86 Correct 301 ms 11116 KB Output is correct
87 Correct 332 ms 10952 KB Output is correct
88 Correct 459 ms 12204 KB Output is correct
89 Correct 417 ms 11084 KB Output is correct
90 Correct 358 ms 12716 KB Output is correct
91 Correct 184 ms 9656 KB Output is correct
92 Correct 428 ms 11528 KB Output is correct
93 Correct 373 ms 12568 KB Output is correct
94 Correct 634 ms 14428 KB Output is correct
95 Correct 345 ms 19748 KB Output is correct
96 Correct 246 ms 19112 KB Output is correct
97 Correct 257 ms 14376 KB Output is correct
98 Correct 328 ms 14432 KB Output is correct
99 Correct 334 ms 13360 KB Output is correct
100 Correct 363 ms 16300 KB Output is correct
101 Correct 490 ms 13816 KB Output is correct
102 Correct 421 ms 15240 KB Output is correct
103 Correct 368 ms 16560 KB Output is correct
104 Correct 275 ms 12976 KB Output is correct
105 Correct 445 ms 14820 KB Output is correct
106 Correct 586 ms 15836 KB Output is correct
107 Correct 147 ms 20004 KB Output is correct
108 Correct 634 ms 14160 KB Output is correct
109 Correct 633 ms 14284 KB Output is correct
110 Correct 649 ms 14156 KB Output is correct
111 Correct 640 ms 14160 KB Output is correct
112 Correct 650 ms 14288 KB Output is correct
113 Correct 624 ms 14220 KB Output is correct
114 Correct 635 ms 14252 KB Output is correct
115 Correct 656 ms 14156 KB Output is correct
116 Correct 630 ms 14156 KB Output is correct