Submission #254807

# Submission time Handle Problem Language Result Execution time Memory
254807 2020-07-30T15:52:59 Z imeimi2000 Joker (BOI20_joker) C++17
100 / 100
560 ms 8292 KB
#include <bits/stdc++.h>

using namespace std;

int n, m, q;
int X[200002], Y[200002];

vector<int> op;
int par[400005], sz[400005];

void restore(int psz) {
    while (psz < int(op.size())) {
        int x = op.back();
        op.pop_back();
        sz[par[x]] -= sz[x];
        par[x] = x;
    }
}

int find(int x) {
    return par[x] != x ? find(par[x]) : x;
}

void merge(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (sz[x] < sz[y]) swap(x, y);
    par[y] = x;
    sz[x] += sz[y];
    op.push_back(y);
}

bool merge_v(int x, int y) {
    --x, --y;
    merge(x << 1 | 0, y << 1 | 1);
    merge(x << 1 | 1, y << 1 | 0);
    return (find(x << 1 | 0) == find(x << 1 | 1));
}

int mv[200001];
void solve(int s, int e, int x, int y, bool odd) {
    if (s > e) return;
    int psz = op.size();
    int m = (s + e) / 2;
    bool nodd = odd;
    for (int i = m; i <= min(e, ::m); ++i) nodd |= merge_v(X[i], Y[i]);
    if (nodd) mv[m] = x;
    else for (int i = x + 1; i <= y; ++i) {
        nodd |= merge_v(X[i], Y[i]);
        if (nodd) {
            mv[m] = i;
            break;
        }
    }
    restore(psz);
    nodd = odd;
    for (int i = m; i <= min(e, ::m); ++i) nodd |= merge_v(X[i], Y[i]);
    solve(s, m - 1, x, mv[m], nodd);
    restore(psz);
    nodd = odd;
    for (int i = x + 1; i <= mv[m]; ++i) nodd |= merge_v(X[i], Y[i]);
    solve(m + 1, e, mv[m], y, nodd);
    restore(psz);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> q;
    for (int i = 1; i <= m; ++i) {
        cin >> X[i] >> Y[i];
    }
    X[m + 1] = Y[m + 1] = 1;
    for (int i = 0; i < n + n; ++i) par[i] = i, sz[i] = 1;
    solve(1, m + 1, 0, m + 1, 0);
    while (q--) {
        int l, r;
        cin >> l >> r;
        printf(l - 1 >= mv[r + 1] ? "YES\n" : "NO\n");
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 488 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 318 ms 5852 KB Output is correct
4 Correct 351 ms 8164 KB Output is correct
5 Correct 330 ms 7788 KB Output is correct
6 Correct 279 ms 5868 KB Output is correct
7 Correct 304 ms 5868 KB Output is correct
8 Correct 376 ms 4980 KB Output is correct
9 Correct 433 ms 5996 KB Output is correct
10 Correct 523 ms 8044 KB Output is correct
11 Correct 375 ms 5872 KB Output is correct
12 Correct 439 ms 7648 KB Output is correct
13 Correct 327 ms 3884 KB Output is correct
14 Correct 387 ms 4976 KB Output is correct
15 Correct 486 ms 6632 KB Output is correct
16 Correct 538 ms 8148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 318 ms 5852 KB Output is correct
30 Correct 351 ms 8164 KB Output is correct
31 Correct 330 ms 7788 KB Output is correct
32 Correct 279 ms 5868 KB Output is correct
33 Correct 304 ms 5868 KB Output is correct
34 Correct 376 ms 4980 KB Output is correct
35 Correct 433 ms 5996 KB Output is correct
36 Correct 523 ms 8044 KB Output is correct
37 Correct 375 ms 5872 KB Output is correct
38 Correct 439 ms 7648 KB Output is correct
39 Correct 327 ms 3884 KB Output is correct
40 Correct 387 ms 4976 KB Output is correct
41 Correct 486 ms 6632 KB Output is correct
42 Correct 538 ms 8148 KB Output is correct
43 Correct 326 ms 6000 KB Output is correct
44 Correct 337 ms 8168 KB Output is correct
45 Correct 352 ms 8292 KB Output is correct
46 Correct 288 ms 5868 KB Output is correct
47 Correct 306 ms 6000 KB Output is correct
48 Correct 461 ms 6000 KB Output is correct
49 Correct 526 ms 8040 KB Output is correct
50 Correct 354 ms 5360 KB Output is correct
51 Correct 385 ms 6632 KB Output is correct
52 Correct 421 ms 7912 KB Output is correct
53 Correct 327 ms 4088 KB Output is correct
54 Correct 432 ms 5356 KB Output is correct
55 Correct 495 ms 6680 KB Output is correct
56 Correct 553 ms 8040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 488 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
55 Correct 282 ms 5220 KB Output is correct
56 Correct 318 ms 7528 KB Output is correct
57 Correct 276 ms 7016 KB Output is correct
58 Correct 235 ms 5164 KB Output is correct
59 Correct 409 ms 5228 KB Output is correct
60 Correct 473 ms 6640 KB Output is correct
61 Correct 321 ms 5176 KB Output is correct
62 Correct 384 ms 7024 KB Output is correct
63 Correct 310 ms 3828 KB Output is correct
64 Correct 425 ms 5616 KB Output is correct
65 Correct 470 ms 6900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 2 ms 384 KB Output is correct
34 Correct 3 ms 512 KB Output is correct
35 Correct 3 ms 512 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 488 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 3 ms 512 KB Output is correct
47 Correct 3 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 3 ms 384 KB Output is correct
52 Correct 3 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 512 KB Output is correct
55 Correct 318 ms 5852 KB Output is correct
56 Correct 351 ms 8164 KB Output is correct
57 Correct 330 ms 7788 KB Output is correct
58 Correct 279 ms 5868 KB Output is correct
59 Correct 304 ms 5868 KB Output is correct
60 Correct 376 ms 4980 KB Output is correct
61 Correct 433 ms 5996 KB Output is correct
62 Correct 523 ms 8044 KB Output is correct
63 Correct 375 ms 5872 KB Output is correct
64 Correct 439 ms 7648 KB Output is correct
65 Correct 327 ms 3884 KB Output is correct
66 Correct 387 ms 4976 KB Output is correct
67 Correct 486 ms 6632 KB Output is correct
68 Correct 538 ms 8148 KB Output is correct
69 Correct 326 ms 6000 KB Output is correct
70 Correct 337 ms 8168 KB Output is correct
71 Correct 352 ms 8292 KB Output is correct
72 Correct 288 ms 5868 KB Output is correct
73 Correct 306 ms 6000 KB Output is correct
74 Correct 461 ms 6000 KB Output is correct
75 Correct 526 ms 8040 KB Output is correct
76 Correct 354 ms 5360 KB Output is correct
77 Correct 385 ms 6632 KB Output is correct
78 Correct 421 ms 7912 KB Output is correct
79 Correct 327 ms 4088 KB Output is correct
80 Correct 432 ms 5356 KB Output is correct
81 Correct 495 ms 6680 KB Output is correct
82 Correct 553 ms 8040 KB Output is correct
83 Correct 282 ms 5220 KB Output is correct
84 Correct 318 ms 7528 KB Output is correct
85 Correct 276 ms 7016 KB Output is correct
86 Correct 235 ms 5164 KB Output is correct
87 Correct 409 ms 5228 KB Output is correct
88 Correct 473 ms 6640 KB Output is correct
89 Correct 321 ms 5176 KB Output is correct
90 Correct 384 ms 7024 KB Output is correct
91 Correct 310 ms 3828 KB Output is correct
92 Correct 425 ms 5616 KB Output is correct
93 Correct 470 ms 6900 KB Output is correct
94 Correct 329 ms 5924 KB Output is correct
95 Correct 447 ms 8096 KB Output is correct
96 Correct 343 ms 7712 KB Output is correct
97 Correct 296 ms 5872 KB Output is correct
98 Correct 332 ms 5876 KB Output is correct
99 Correct 404 ms 5056 KB Output is correct
100 Correct 489 ms 8080 KB Output is correct
101 Correct 386 ms 5452 KB Output is correct
102 Correct 400 ms 6760 KB Output is correct
103 Correct 459 ms 8076 KB Output is correct
104 Correct 377 ms 4468 KB Output is correct
105 Correct 493 ms 6508 KB Output is correct
106 Correct 560 ms 7784 KB Output is correct
107 Correct 241 ms 8168 KB Output is correct
108 Correct 346 ms 5772 KB Output is correct
109 Correct 324 ms 5872 KB Output is correct
110 Correct 329 ms 5872 KB Output is correct
111 Correct 325 ms 5820 KB Output is correct
112 Correct 333 ms 6000 KB Output is correct
113 Correct 331 ms 5872 KB Output is correct
114 Correct 344 ms 5868 KB Output is correct
115 Correct 330 ms 5872 KB Output is correct
116 Correct 329 ms 5780 KB Output is correct