답안 #573142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573142 2022-06-06T04:36:12 Z tengiz05 Joker (BOI20_joker) C++17
100 / 100
342 ms 14716 KB
#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n, m, q;
    std::cin >> n >> m >> q;
    
    std::vector<int> from(m), to(m);
    for (int i = 0; i < m; i++) {
        std::cin >> from[i] >> to[i];
        from[i]--;
        to[i]--;
    }
    
    std::vector<int> p(n), c(n), siz(n, 1);
    std::iota(p.begin(), p.end(), 0);
    
    auto leader = [&](int u) {
        while (u != p[u]) u = p[u];
        return u;
    };
    
    auto color = [&](int u) {
        int x = c[u];
        while (u != p[u]) {
            u = p[u];
            x ^= c[u];
        }
        return x;
    };
    
    int cnt = 0;
    
    std::vector<std::tuple<int, int, int, int>> h;
    
    auto merge = [&](int id) {
        int u = from[id];
        int v = to[id];
        int a = leader(u);
        int b = leader(v);
        h.emplace_back(id, a, b, color(u) == color(v));
        if (a == b) {
            if (color(u) == color(v)) {
                cnt++;
            }
        } else {
            if (siz[a] < siz[b]) {
                std::swap(a, b);
            }
            if (color(u) == color(v)) {
                c[b] ^= 1;
            }
            c[b] ^= c[a];
            siz[a] += siz[b];
            p[b] = a;
        }
        return;
    };
    
    auto unmerge = [&]() {
        auto [id, a, b, col] = h.back();
        h.pop_back();
        if (a == b) {
            if (col) {
                cnt--;
            }
        } else {
            if (siz[a] < siz[b]) {
                std::swap(a, b);
            }
            siz[a] -= siz[b];
            p[b] = b;
        }
    };
    auto rollback = [&](int x) {
        while (x--) {
            assert(!h.empty());
            unmerge();
        }
    };
    
    std::vector<int> opt(m);
    
    std::function<void(int, int, int, int)> dfs = [&](int l, int r, int optl, int optr) {
        if (l > r)
            return;
        int m = (l + r) / 2;
        
        for (int i = l; i < m; i++) {
            merge(i);
        }
        
        opt[m] = optr;
        while (cnt == 0 && opt[m] >= optl) {
            merge(opt[m]);
            opt[m]--;
        }
        
        rollback(optr - opt[m]);
        merge(m);
        dfs(m + 1, r, opt[m], optr);
        rollback(m - l + 1);
        
        for (int i = opt[m] + 1; i <= optr; i++) {
            merge(i);
        }
        dfs(l, m - 1, optl, opt[m]);
        rollback(optr - opt[m]);
    };
    
    dfs(0, m - 1, 0, m - 1);
    
    while (q--) {
        int l, r;
        std::cin >> l >> r;
        l--;
        r--;
        
        if (r <= opt[l]) {
            std::cout << "YES\n";
        } else {
            std::cout << "NO\n";
        }
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 424 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 340 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 215 ms 8020 KB Output is correct
4 Correct 301 ms 13360 KB Output is correct
5 Correct 164 ms 9028 KB Output is correct
6 Correct 209 ms 9276 KB Output is correct
7 Correct 212 ms 9284 KB Output is correct
8 Correct 224 ms 8860 KB Output is correct
9 Correct 255 ms 9296 KB Output is correct
10 Correct 321 ms 10452 KB Output is correct
11 Correct 241 ms 9284 KB Output is correct
12 Correct 264 ms 10216 KB Output is correct
13 Correct 220 ms 8400 KB Output is correct
14 Correct 233 ms 8800 KB Output is correct
15 Correct 321 ms 9832 KB Output is correct
16 Correct 336 ms 10448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 215 ms 8020 KB Output is correct
30 Correct 301 ms 13360 KB Output is correct
31 Correct 164 ms 9028 KB Output is correct
32 Correct 209 ms 9276 KB Output is correct
33 Correct 212 ms 9284 KB Output is correct
34 Correct 224 ms 8860 KB Output is correct
35 Correct 255 ms 9296 KB Output is correct
36 Correct 321 ms 10452 KB Output is correct
37 Correct 241 ms 9284 KB Output is correct
38 Correct 264 ms 10216 KB Output is correct
39 Correct 220 ms 8400 KB Output is correct
40 Correct 233 ms 8800 KB Output is correct
41 Correct 321 ms 9832 KB Output is correct
42 Correct 336 ms 10448 KB Output is correct
43 Correct 217 ms 9036 KB Output is correct
44 Correct 312 ms 13740 KB Output is correct
45 Correct 291 ms 10576 KB Output is correct
46 Correct 218 ms 9132 KB Output is correct
47 Correct 218 ms 9280 KB Output is correct
48 Correct 278 ms 9232 KB Output is correct
49 Correct 336 ms 10388 KB Output is correct
50 Correct 246 ms 9184 KB Output is correct
51 Correct 262 ms 9564 KB Output is correct
52 Correct 292 ms 10564 KB Output is correct
53 Correct 228 ms 8208 KB Output is correct
54 Correct 279 ms 9156 KB Output is correct
55 Correct 312 ms 9948 KB Output is correct
56 Correct 340 ms 10608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 424 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 340 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 3 ms 340 KB Output is correct
55 Correct 184 ms 8004 KB Output is correct
56 Correct 272 ms 14716 KB Output is correct
57 Correct 136 ms 10432 KB Output is correct
58 Correct 176 ms 9420 KB Output is correct
59 Correct 244 ms 9440 KB Output is correct
60 Correct 318 ms 10180 KB Output is correct
61 Correct 237 ms 9412 KB Output is correct
62 Correct 250 ms 10196 KB Output is correct
63 Correct 187 ms 8772 KB Output is correct
64 Correct 264 ms 9664 KB Output is correct
65 Correct 314 ms 10244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 424 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 2 ms 468 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 2 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 2 ms 340 KB Output is correct
50 Correct 2 ms 340 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 340 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 3 ms 340 KB Output is correct
55 Correct 215 ms 8020 KB Output is correct
56 Correct 301 ms 13360 KB Output is correct
57 Correct 164 ms 9028 KB Output is correct
58 Correct 209 ms 9276 KB Output is correct
59 Correct 212 ms 9284 KB Output is correct
60 Correct 224 ms 8860 KB Output is correct
61 Correct 255 ms 9296 KB Output is correct
62 Correct 321 ms 10452 KB Output is correct
63 Correct 241 ms 9284 KB Output is correct
64 Correct 264 ms 10216 KB Output is correct
65 Correct 220 ms 8400 KB Output is correct
66 Correct 233 ms 8800 KB Output is correct
67 Correct 321 ms 9832 KB Output is correct
68 Correct 336 ms 10448 KB Output is correct
69 Correct 217 ms 9036 KB Output is correct
70 Correct 312 ms 13740 KB Output is correct
71 Correct 291 ms 10576 KB Output is correct
72 Correct 218 ms 9132 KB Output is correct
73 Correct 218 ms 9280 KB Output is correct
74 Correct 278 ms 9232 KB Output is correct
75 Correct 336 ms 10388 KB Output is correct
76 Correct 246 ms 9184 KB Output is correct
77 Correct 262 ms 9564 KB Output is correct
78 Correct 292 ms 10564 KB Output is correct
79 Correct 228 ms 8208 KB Output is correct
80 Correct 279 ms 9156 KB Output is correct
81 Correct 312 ms 9948 KB Output is correct
82 Correct 340 ms 10608 KB Output is correct
83 Correct 184 ms 8004 KB Output is correct
84 Correct 272 ms 14716 KB Output is correct
85 Correct 136 ms 10432 KB Output is correct
86 Correct 176 ms 9420 KB Output is correct
87 Correct 244 ms 9440 KB Output is correct
88 Correct 318 ms 10180 KB Output is correct
89 Correct 237 ms 9412 KB Output is correct
90 Correct 250 ms 10196 KB Output is correct
91 Correct 187 ms 8772 KB Output is correct
92 Correct 264 ms 9664 KB Output is correct
93 Correct 314 ms 10244 KB Output is correct
94 Correct 229 ms 9356 KB Output is correct
95 Correct 266 ms 10576 KB Output is correct
96 Correct 170 ms 10436 KB Output is correct
97 Correct 212 ms 9200 KB Output is correct
98 Correct 231 ms 9408 KB Output is correct
99 Correct 249 ms 8920 KB Output is correct
100 Correct 300 ms 10564 KB Output is correct
101 Correct 240 ms 9168 KB Output is correct
102 Correct 289 ms 9884 KB Output is correct
103 Correct 317 ms 10712 KB Output is correct
104 Correct 238 ms 8772 KB Output is correct
105 Correct 313 ms 9740 KB Output is correct
106 Correct 342 ms 10224 KB Output is correct
107 Correct 154 ms 10512 KB Output is correct
108 Correct 221 ms 9300 KB Output is correct
109 Correct 216 ms 9156 KB Output is correct
110 Correct 224 ms 9156 KB Output is correct
111 Correct 217 ms 9120 KB Output is correct
112 Correct 221 ms 9224 KB Output is correct
113 Correct 220 ms 8652 KB Output is correct
114 Correct 218 ms 9028 KB Output is correct
115 Correct 223 ms 9048 KB Output is correct
116 Correct 221 ms 9004 KB Output is correct