답안 #559767

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
559767 2022-05-10T14:27:17 Z hoanghq2004 Joker (BOI20_joker) C++14
100 / 100
928 ms 65996 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define HaiYen

using namespace std;

const int N = 4e5 + 10;

int n, m, q, last[N], ti, num;
int par[N], sz[N];

struct edge {
    int u, v;
} e[N];

struct version {
    int ti, u, par, sz;
} old[N * 40];

int ok[N];

inline int Find(int u) {
    if (u == par[u]) return u;
    old[num++] = {ti, u, par[u], sz[u]};
    return par[u] = Find(par[u]);
}

inline void Union(int u, int v) {
    if ((u = Find(u)) == (v = Find(v))) return;
    old[num++] = {ti, u, par[u], sz[u]};
    old[num++] = {ti, v, par[v], sz[v]};
    if (sz[u] < sz[v]) swap(u, v);
    sz[u] += sz[v];
    par[v] = u;
}

inline void rollback() {
    while (num && old[num - 1].ti == ti) {
        auto [_ti, u, _par, _sz] = old[--num];
        par[u] = _par, sz[u] = _sz;
    }
    --ti;
}

struct dta {
    int L, R, u, v;
};

inline void new_v() {
    ++ti;
    ok[ti] = ok[ti - 1];
}

inline void merge(int u, int v) {
    Union(u << 1 ^ 0, v << 1 ^ 1);
    Union(u << 1 ^ 1, v << 1 ^ 0);
    if (Find(u << 1 ^ 0) == Find(u << 1 ^ 1)) ok[ti] = 1;
    if (Find(v << 1 ^ 0) == Find(v << 1 ^ 1)) ok[ti] = 1;
}

inline void divide(int L, int R, int from, int to) {
    if (L > R) return;
    int mid = L + R >> 1;
    new_v();
    for (int i = L; i <= mid; ++i) merge(e[i].u, e[i].v);
    new_v();
    for (int i = to; i >= from; --i) {
        merge(e[i].u, e[i].v);
        if (ok[ti]) {
            last[mid] = i;
            break;
        }
    }
    rollback();
    divide(mid + 1, R, last[mid], to);
    rollback();
    new_v();
    for (int i = to; i > last[mid]; --i) merge(e[i].u, e[i].v);
    divide(L, mid - 1, from, last[mid]);
    rollback();
}

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> q;
    for (int i = 1; i <= m; ++i) cin >> e[i].u >> e[i].v;
    e[m + 1] = {n + 1, n + 2};
    e[0] = {n + 1, n + 2};
    for (int i = 1; i <= 2 * n + 4; ++i) par[i] = i, sz[i] = 1;
    divide(0, m, 1, m + 1);
    while (q--) {
        int l, r;
        cin >> l >> r;
        if (last[l - 1] >= r + 1) cout << "YES\n";
        else cout << "NO\n";
    }
}

Compilation message

Joker.cpp: In function 'void rollback()':
Joker.cpp:40:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |         auto [_ti, u, _par, _sz] = old[--num];
      |              ^
Joker.cpp: In function 'void divide(int, int, int, int)':
Joker.cpp:64:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |     int mid = L + R >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 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 340 KB Output is correct
12 Correct 1 ms 328 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 340 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 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 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 340 KB Output is correct
12 Correct 1 ms 328 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 340 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 3 ms 596 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 3 ms 596 KB Output is correct
34 Correct 3 ms 724 KB Output is correct
35 Correct 4 ms 752 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 4 ms 724 KB Output is correct
38 Correct 5 ms 1012 KB Output is correct
39 Correct 3 ms 728 KB Output is correct
40 Correct 3 ms 640 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 3 ms 724 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 3 ms 728 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 4 ms 644 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 3 ms 724 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 4 ms 728 KB Output is correct
51 Correct 3 ms 724 KB Output is correct
52 Correct 3 ms 728 KB Output is correct
53 Correct 3 ms 724 KB Output is correct
54 Correct 4 ms 752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 383 ms 38580 KB Output is correct
4 Correct 912 ms 65484 KB Output is correct
5 Correct 267 ms 41644 KB Output is correct
6 Correct 331 ms 40036 KB Output is correct
7 Correct 304 ms 39852 KB Output is correct
8 Correct 295 ms 35716 KB Output is correct
9 Correct 361 ms 37704 KB Output is correct
10 Correct 484 ms 39880 KB Output is correct
11 Correct 384 ms 38740 KB Output is correct
12 Correct 420 ms 40004 KB Output is correct
13 Correct 284 ms 33660 KB Output is correct
14 Correct 318 ms 36268 KB Output is correct
15 Correct 450 ms 39480 KB Output is correct
16 Correct 478 ms 40292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 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 340 KB Output is correct
12 Correct 1 ms 328 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 340 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 383 ms 38580 KB Output is correct
30 Correct 912 ms 65484 KB Output is correct
31 Correct 267 ms 41644 KB Output is correct
32 Correct 331 ms 40036 KB Output is correct
33 Correct 304 ms 39852 KB Output is correct
34 Correct 295 ms 35716 KB Output is correct
35 Correct 361 ms 37704 KB Output is correct
36 Correct 484 ms 39880 KB Output is correct
37 Correct 384 ms 38740 KB Output is correct
38 Correct 420 ms 40004 KB Output is correct
39 Correct 284 ms 33660 KB Output is correct
40 Correct 318 ms 36268 KB Output is correct
41 Correct 450 ms 39480 KB Output is correct
42 Correct 478 ms 40292 KB Output is correct
43 Correct 386 ms 38900 KB Output is correct
44 Correct 928 ms 65996 KB Output is correct
45 Correct 528 ms 42052 KB Output is correct
46 Correct 296 ms 40272 KB Output is correct
47 Correct 296 ms 40280 KB Output is correct
48 Correct 376 ms 38284 KB Output is correct
49 Correct 514 ms 40356 KB Output is correct
50 Correct 383 ms 38368 KB Output is correct
51 Correct 391 ms 39960 KB Output is correct
52 Correct 429 ms 40400 KB Output is correct
53 Correct 291 ms 33880 KB Output is correct
54 Correct 353 ms 37700 KB Output is correct
55 Correct 440 ms 39880 KB Output is correct
56 Correct 474 ms 40576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 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 340 KB Output is correct
12 Correct 1 ms 328 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 340 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 3 ms 596 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 3 ms 596 KB Output is correct
34 Correct 3 ms 724 KB Output is correct
35 Correct 4 ms 752 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 4 ms 724 KB Output is correct
38 Correct 5 ms 1012 KB Output is correct
39 Correct 3 ms 728 KB Output is correct
40 Correct 3 ms 640 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 3 ms 724 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 3 ms 728 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 4 ms 644 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 3 ms 724 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 4 ms 728 KB Output is correct
51 Correct 3 ms 724 KB Output is correct
52 Correct 3 ms 728 KB Output is correct
53 Correct 3 ms 724 KB Output is correct
54 Correct 4 ms 752 KB Output is correct
55 Correct 355 ms 36248 KB Output is correct
56 Correct 849 ms 64048 KB Output is correct
57 Correct 227 ms 39244 KB Output is correct
58 Correct 247 ms 37512 KB Output is correct
59 Correct 339 ms 35908 KB Output is correct
60 Correct 435 ms 37760 KB Output is correct
61 Correct 383 ms 36552 KB Output is correct
62 Correct 364 ms 37824 KB Output is correct
63 Correct 239 ms 32728 KB Output is correct
64 Correct 379 ms 36780 KB Output is correct
65 Correct 410 ms 37940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 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 340 KB Output is correct
12 Correct 1 ms 328 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 340 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 3 ms 596 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 3 ms 596 KB Output is correct
34 Correct 3 ms 724 KB Output is correct
35 Correct 4 ms 752 KB Output is correct
36 Correct 3 ms 724 KB Output is correct
37 Correct 4 ms 724 KB Output is correct
38 Correct 5 ms 1012 KB Output is correct
39 Correct 3 ms 728 KB Output is correct
40 Correct 3 ms 640 KB Output is correct
41 Correct 3 ms 724 KB Output is correct
42 Correct 3 ms 724 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 3 ms 728 KB Output is correct
45 Correct 3 ms 724 KB Output is correct
46 Correct 4 ms 644 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 3 ms 724 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 4 ms 728 KB Output is correct
51 Correct 3 ms 724 KB Output is correct
52 Correct 3 ms 728 KB Output is correct
53 Correct 3 ms 724 KB Output is correct
54 Correct 4 ms 752 KB Output is correct
55 Correct 383 ms 38580 KB Output is correct
56 Correct 912 ms 65484 KB Output is correct
57 Correct 267 ms 41644 KB Output is correct
58 Correct 331 ms 40036 KB Output is correct
59 Correct 304 ms 39852 KB Output is correct
60 Correct 295 ms 35716 KB Output is correct
61 Correct 361 ms 37704 KB Output is correct
62 Correct 484 ms 39880 KB Output is correct
63 Correct 384 ms 38740 KB Output is correct
64 Correct 420 ms 40004 KB Output is correct
65 Correct 284 ms 33660 KB Output is correct
66 Correct 318 ms 36268 KB Output is correct
67 Correct 450 ms 39480 KB Output is correct
68 Correct 478 ms 40292 KB Output is correct
69 Correct 386 ms 38900 KB Output is correct
70 Correct 928 ms 65996 KB Output is correct
71 Correct 528 ms 42052 KB Output is correct
72 Correct 296 ms 40272 KB Output is correct
73 Correct 296 ms 40280 KB Output is correct
74 Correct 376 ms 38284 KB Output is correct
75 Correct 514 ms 40356 KB Output is correct
76 Correct 383 ms 38368 KB Output is correct
77 Correct 391 ms 39960 KB Output is correct
78 Correct 429 ms 40400 KB Output is correct
79 Correct 291 ms 33880 KB Output is correct
80 Correct 353 ms 37700 KB Output is correct
81 Correct 440 ms 39880 KB Output is correct
82 Correct 474 ms 40576 KB Output is correct
83 Correct 355 ms 36248 KB Output is correct
84 Correct 849 ms 64048 KB Output is correct
85 Correct 227 ms 39244 KB Output is correct
86 Correct 247 ms 37512 KB Output is correct
87 Correct 339 ms 35908 KB Output is correct
88 Correct 435 ms 37760 KB Output is correct
89 Correct 383 ms 36552 KB Output is correct
90 Correct 364 ms 37824 KB Output is correct
91 Correct 239 ms 32728 KB Output is correct
92 Correct 379 ms 36780 KB Output is correct
93 Correct 410 ms 37940 KB Output is correct
94 Correct 409 ms 39664 KB Output is correct
95 Correct 420 ms 42848 KB Output is correct
96 Correct 294 ms 42624 KB Output is correct
97 Correct 289 ms 41000 KB Output is correct
98 Correct 340 ms 40960 KB Output is correct
99 Correct 327 ms 37296 KB Output is correct
100 Correct 498 ms 41440 KB Output is correct
101 Correct 351 ms 39080 KB Output is correct
102 Correct 445 ms 40792 KB Output is correct
103 Correct 452 ms 41176 KB Output is correct
104 Correct 320 ms 36044 KB Output is correct
105 Correct 412 ms 40204 KB Output is correct
106 Correct 471 ms 41252 KB Output is correct
107 Correct 235 ms 30548 KB Output is correct
108 Correct 360 ms 39328 KB Output is correct
109 Correct 416 ms 39412 KB Output is correct
110 Correct 410 ms 39476 KB Output is correct
111 Correct 366 ms 39468 KB Output is correct
112 Correct 413 ms 39432 KB Output is correct
113 Correct 383 ms 39400 KB Output is correct
114 Correct 361 ms 39384 KB Output is correct
115 Correct 417 ms 39336 KB Output is correct
116 Correct 394 ms 39472 KB Output is correct