답안 #308238

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308238 2020-09-30T13:02:15 Z VEGAnn Joker (BOI20_joker) C++14
100 / 100
285 ms 13540 KB
#include <bits/stdc++.h>
#define i2 array<int,2>
#define i3 array<int,3>
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
const int N = 200100;
const int M = 200100;
vector<i3> rollbacks;
int n, m, q, pre[N], siz[N], U[M], V[M], bnd[N], ht[N];
bool bad = 0;

i2 get(int x) {
    i2 res = {0, 0};

    while (x != pre[x]){
        res[1] ^= ht[x];
        x = pre[x];
    }

    res[0] = x;

    return res;
}

void link(int id){
    i2 x = get(U[id]), y = get(V[id]);

    if (x[0] == y[0]){
        if ((x[1] ^ y[1] ^ 1))
            bad = 1;
    } else {
        if (siz[x[0]] > siz[y[0]]) swap(x, y);

        // make new rollback

        rollbacks.PB({x[0], y[0], ht[x[0]]});

        siz[y[0]] += siz[x[0]];
        pre[x[0]] = y[0];
        ht[x[0]] ^= (x[1] ^ y[1] ^ 1);
    }
}

void calc(int l, int r, int cand_l, int cand_r){
    // cand_r < n

    int md = (l + r) >> 1;

    int mem = sz(rollbacks), res = 0;

    assert(!bad);

    for (int i = l; i < md; i++) {
        link(i);

        if (bad) {
            res = cand_r;
            break;
        }
    }

    for (int i = min(m - 1, cand_r); i >= max(cand_l, md); i--){
        if (bad) break;

        link(i);

        if (bad) {
            res = i;
            break;
        }
    }

    bnd[md] = res;
    bad = 0;

    while (sz(rollbacks) > mem){
        i3 cur = rollbacks.back(); rollbacks.pop_back();

        int x = cur[0], y = cur[1];

        ht[x] = cur[2];
        siz[y] -= siz[x];
        pre[x] = x;
    }

    if (l < md){
        for (int i = min(m - 1, cand_r); i > res; i--){
            link(i);

            if (bad) break;
        }

        if (bad){
            for (int i = l; i < md; i++)
                bnd[i] = res;
            bad = 0;
        } else calc(l, md - 1, cand_l, res);

        while (sz(rollbacks) > mem){
            i3 cur = rollbacks.back(); rollbacks.pop_back();

            int x = cur[0], y = cur[1];

            ht[x] = cur[2];
            siz[y] -= siz[x];
            pre[x] = x;
        }
    }

    if (r > md){
        for (int i = l; i < md + 1; i++){
            link(i);

            if (bad) break;
        }

        if (bad){
            for (int i = r; i > md; i--)
                bnd[i] = cand_r;
            bad = 0;
        } else calc(md + 1, r, max(md + 1, res), cand_r);

        while (sz(rollbacks) > mem){
            i3 cur = rollbacks.back(); rollbacks.pop_back();

            int x = cur[0], y = cur[1];

            ht[x] = cur[2];
            siz[y] -= siz[x];
            pre[x] = x;
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m >> q;

    for (int i = 0; i < n; i++){
        pre[i] = i;
        siz[i] = 1;
        ht[i] = 0;
    }

    for (int i = 0; i < m; i++){
        cin >> U[i] >> V[i];
        U[i]--; V[i]--;
    }

    calc(0, m - 1, 0, m);

    for (int i = 0; i < q; i++){
        int l, r; cin >> l >> r; l--; r--;

        cout << (bnd[l] <= r ? "NO\n" : "YES\n");
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 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 512 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 512 KB Output is correct
19 Correct 1 ms 384 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 392 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 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 512 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 512 KB Output is correct
19 Correct 1 ms 384 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 392 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 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 504 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 2 ms 508 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 2 ms 512 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 187 ms 9924 KB Output is correct
4 Correct 273 ms 11652 KB Output is correct
5 Correct 203 ms 12004 KB Output is correct
6 Correct 182 ms 9836 KB Output is correct
7 Correct 172 ms 9960 KB Output is correct
8 Correct 182 ms 8300 KB Output is correct
9 Correct 204 ms 9124 KB Output is correct
10 Correct 267 ms 10728 KB Output is correct
11 Correct 192 ms 9580 KB Output is correct
12 Correct 245 ms 10988 KB Output is correct
13 Correct 176 ms 7792 KB Output is correct
14 Correct 184 ms 8944 KB Output is correct
15 Correct 239 ms 10220 KB Output is correct
16 Correct 256 ms 11116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 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 512 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 512 KB Output is correct
19 Correct 1 ms 384 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 392 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 187 ms 9924 KB Output is correct
30 Correct 273 ms 11652 KB Output is correct
31 Correct 203 ms 12004 KB Output is correct
32 Correct 182 ms 9836 KB Output is correct
33 Correct 172 ms 9960 KB Output is correct
34 Correct 182 ms 8300 KB Output is correct
35 Correct 204 ms 9124 KB Output is correct
36 Correct 267 ms 10728 KB Output is correct
37 Correct 192 ms 9580 KB Output is correct
38 Correct 245 ms 10988 KB Output is correct
39 Correct 176 ms 7792 KB Output is correct
40 Correct 184 ms 8944 KB Output is correct
41 Correct 239 ms 10220 KB Output is correct
42 Correct 256 ms 11116 KB Output is correct
43 Correct 186 ms 10164 KB Output is correct
44 Correct 244 ms 12220 KB Output is correct
45 Correct 285 ms 12512 KB Output is correct
46 Correct 156 ms 10236 KB Output is correct
47 Correct 160 ms 10220 KB Output is correct
48 Correct 215 ms 9576 KB Output is correct
49 Correct 251 ms 11240 KB Output is correct
50 Correct 192 ms 9580 KB Output is correct
51 Correct 205 ms 10732 KB Output is correct
52 Correct 227 ms 11628 KB Output is correct
53 Correct 178 ms 8052 KB Output is correct
54 Correct 209 ms 9624 KB Output is correct
55 Correct 240 ms 10856 KB Output is correct
56 Correct 254 ms 11500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 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 512 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 512 KB Output is correct
19 Correct 1 ms 384 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 392 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 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 504 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 2 ms 508 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 2 ms 512 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 143 ms 7528 KB Output is correct
56 Correct 188 ms 10080 KB Output is correct
57 Correct 157 ms 10216 KB Output is correct
58 Correct 117 ms 7468 KB Output is correct
59 Correct 170 ms 7404 KB Output is correct
60 Correct 208 ms 8424 KB Output is correct
61 Correct 166 ms 7400 KB Output is correct
62 Correct 177 ms 8680 KB Output is correct
63 Correct 135 ms 6000 KB Output is correct
64 Correct 184 ms 7660 KB Output is correct
65 Correct 212 ms 8680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 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 512 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 512 KB Output is correct
19 Correct 1 ms 384 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 392 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 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 2 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 3 ms 512 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 3 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 2 ms 504 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 2 ms 512 KB Output is correct
49 Correct 2 ms 504 KB Output is correct
50 Correct 2 ms 512 KB Output is correct
51 Correct 2 ms 508 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 2 ms 512 KB Output is correct
54 Correct 2 ms 512 KB Output is correct
55 Correct 187 ms 9924 KB Output is correct
56 Correct 273 ms 11652 KB Output is correct
57 Correct 203 ms 12004 KB Output is correct
58 Correct 182 ms 9836 KB Output is correct
59 Correct 172 ms 9960 KB Output is correct
60 Correct 182 ms 8300 KB Output is correct
61 Correct 204 ms 9124 KB Output is correct
62 Correct 267 ms 10728 KB Output is correct
63 Correct 192 ms 9580 KB Output is correct
64 Correct 245 ms 10988 KB Output is correct
65 Correct 176 ms 7792 KB Output is correct
66 Correct 184 ms 8944 KB Output is correct
67 Correct 239 ms 10220 KB Output is correct
68 Correct 256 ms 11116 KB Output is correct
69 Correct 186 ms 10164 KB Output is correct
70 Correct 244 ms 12220 KB Output is correct
71 Correct 285 ms 12512 KB Output is correct
72 Correct 156 ms 10236 KB Output is correct
73 Correct 160 ms 10220 KB Output is correct
74 Correct 215 ms 9576 KB Output is correct
75 Correct 251 ms 11240 KB Output is correct
76 Correct 192 ms 9580 KB Output is correct
77 Correct 205 ms 10732 KB Output is correct
78 Correct 227 ms 11628 KB Output is correct
79 Correct 178 ms 8052 KB Output is correct
80 Correct 209 ms 9624 KB Output is correct
81 Correct 240 ms 10856 KB Output is correct
82 Correct 254 ms 11500 KB Output is correct
83 Correct 143 ms 7528 KB Output is correct
84 Correct 188 ms 10080 KB Output is correct
85 Correct 157 ms 10216 KB Output is correct
86 Correct 117 ms 7468 KB Output is correct
87 Correct 170 ms 7404 KB Output is correct
88 Correct 208 ms 8424 KB Output is correct
89 Correct 166 ms 7400 KB Output is correct
90 Correct 177 ms 8680 KB Output is correct
91 Correct 135 ms 6000 KB Output is correct
92 Correct 184 ms 7660 KB Output is correct
93 Correct 212 ms 8680 KB Output is correct
94 Correct 197 ms 10856 KB Output is correct
95 Correct 285 ms 13280 KB Output is correct
96 Correct 206 ms 12880 KB Output is correct
97 Correct 165 ms 10888 KB Output is correct
98 Correct 173 ms 10992 KB Output is correct
99 Correct 207 ms 9832 KB Output is correct
100 Correct 235 ms 12264 KB Output is correct
101 Correct 195 ms 10344 KB Output is correct
102 Correct 226 ms 11368 KB Output is correct
103 Correct 265 ms 12392 KB Output is correct
104 Correct 191 ms 9328 KB Output is correct
105 Correct 239 ms 10988 KB Output is correct
106 Correct 264 ms 12216 KB Output is correct
107 Correct 155 ms 13540 KB Output is correct
108 Correct 196 ms 10728 KB Output is correct
109 Correct 193 ms 10600 KB Output is correct
110 Correct 189 ms 10600 KB Output is correct
111 Correct 194 ms 10600 KB Output is correct
112 Correct 193 ms 10596 KB Output is correct
113 Correct 194 ms 10600 KB Output is correct
114 Correct 195 ms 10732 KB Output is correct
115 Correct 202 ms 10604 KB Output is correct
116 Correct 200 ms 10616 KB Output is correct