Submission #1046776

# Submission time Handle Problem Language Result Execution time Memory
1046776 2024-08-06T22:50:14 Z ortsac Joker (BOI20_joker) C++17
71 / 100
2000 ms 19972 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define pii pair<int, int>
#define fr first
#define se second
 
int block = 4472;
vector<pii> arestas;
int n, m, q;
vector<int> h;
vector<pii> dad;
struct bOp {
    int x, y;
    pii dady;
    int hx;
    bool isbip;
};
vector<bOp> ops;
bool bip = 1;
 
struct Query {
    int l, r, idx;
};
 
bool comp(Query a, Query b) {
    return a.r < b.r;
}
 
const int lst = 47;
vector<Query> qrs[50];
 
pii find(int x) {
    if (dad[x].fr == x) return dad[x];
    pii y = find(dad[x].fr);
    return {y.fr, y.se^dad[x].se};
}
 
void join(int x, int y) {
    auto a = find(x), b = find(y);
    int xdad = a.fr, ydad = b.fr, cx = a.se, cy = b.se;
    if (h[ydad] >= h[xdad]) swap(xdad, ydad);
    bOp newop;
    newop.y = ydad;
    newop.x = xdad;
    newop.dady = dad[ydad];
    newop.hx = h[xdad];
    newop.isbip = bip;
    ops.push_back(newop);
    if (xdad == ydad) {
        if (cx == cy) bip = 0;
        return;
    }
    // x is always bigger now
    dad[ydad] = {xdad, cx == cy};
    if (h[xdad] == h[ydad]) h[xdad]++;
}
 
void rollback() {
    auto u = ops.back();
    ops.pop_back();
    dad[u.y] = u.dady;
    h[u.x] = u.hx;
    bip = u.isbip;
}
 
// bbin?
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> q;
    arestas.resize(m);
    for (int i = 0; i < m; i++) {
        cin >> arestas[i].fr >> arestas[i].se;
    }
    vector<bool> ans(q);
    for (int i = 0; i < q; i++) {
        Query x;
        cin >> x.l >> x.r;
        x.l--;
        x.r--;
        x.idx = i;
        qrs[x.l / block].push_back(x);
    }
    for (int t = 0; t < lst; t++) {
        if (qrs[t].empty()) continue;
        dad.clear();
        h.clear();
        ops.clear();
        dad.resize(n + 1);
        h.resize(n + 1);
        bip = 1;
        for (int i = 1; i <= n; i++) {
            dad[i] = {i, 0};
        }
        sort(qrs[t].begin(), qrs[t].end(), comp);
        // initial setup
        int bg = t*block;
        for (int i = 0; i < bg; i++) {
            join(arestas[i].fr, arestas[i].se);
        }
        for (int i = m - 1; i > bg; i--) {
            join(arestas[i].fr, arestas[i].se);
        }
        int cr = bg;
        for (auto u : qrs[t]) {
            int l = u.l, r = u.r;
            for (int i = cr + 1; i <= r; i++) {
                rollback();
            }
            cr = r;
            for (int i = bg; i < l; i++) {
                join(arestas[i].fr, arestas[i].se);
            }
            ans[u.idx] = bip;
            for (int i = 0; i < (l - bg); i++) rollback();
        }
    }
    for (auto u : ans) {
        if (u) cout << "NO\n";
        else cout << "YES\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 15 ms 348 KB Output is correct
30 Correct 27 ms 604 KB Output is correct
31 Correct 36 ms 604 KB Output is correct
32 Correct 32 ms 604 KB Output is correct
33 Correct 34 ms 604 KB Output is correct
34 Correct 31 ms 604 KB Output is correct
35 Correct 32 ms 604 KB Output is correct
36 Correct 31 ms 604 KB Output is correct
37 Correct 30 ms 604 KB Output is correct
38 Correct 30 ms 620 KB Output is correct
39 Correct 30 ms 600 KB Output is correct
40 Correct 33 ms 600 KB Output is correct
41 Correct 34 ms 604 KB Output is correct
42 Correct 32 ms 348 KB Output is correct
43 Correct 39 ms 600 KB Output is correct
44 Correct 41 ms 344 KB Output is correct
45 Correct 34 ms 604 KB Output is correct
46 Correct 41 ms 600 KB Output is correct
47 Correct 32 ms 604 KB Output is correct
48 Correct 32 ms 344 KB Output is correct
49 Correct 31 ms 600 KB Output is correct
50 Correct 31 ms 600 KB Output is correct
51 Correct 35 ms 600 KB Output is correct
52 Correct 35 ms 344 KB Output is correct
53 Correct 31 ms 604 KB Output is correct
54 Correct 31 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 55 ms 14664 KB Output is correct
4 Correct 57 ms 18288 KB Output is correct
5 Correct 58 ms 17736 KB Output is correct
6 Correct 56 ms 17876 KB Output is correct
7 Correct 58 ms 17476 KB Output is correct
8 Correct 55 ms 15940 KB Output is correct
9 Correct 57 ms 16052 KB Output is correct
10 Correct 57 ms 16712 KB Output is correct
11 Correct 56 ms 16452 KB Output is correct
12 Correct 57 ms 17876 KB Output is correct
13 Correct 57 ms 16216 KB Output is correct
14 Correct 59 ms 17224 KB Output is correct
15 Correct 63 ms 17992 KB Output is correct
16 Correct 59 ms 18252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 55 ms 14664 KB Output is correct
30 Correct 57 ms 18288 KB Output is correct
31 Correct 58 ms 17736 KB Output is correct
32 Correct 56 ms 17876 KB Output is correct
33 Correct 58 ms 17476 KB Output is correct
34 Correct 55 ms 15940 KB Output is correct
35 Correct 57 ms 16052 KB Output is correct
36 Correct 57 ms 16712 KB Output is correct
37 Correct 56 ms 16452 KB Output is correct
38 Correct 57 ms 17876 KB Output is correct
39 Correct 57 ms 16216 KB Output is correct
40 Correct 59 ms 17224 KB Output is correct
41 Correct 63 ms 17992 KB Output is correct
42 Correct 59 ms 18252 KB Output is correct
43 Correct 356 ms 17276 KB Output is correct
44 Correct 361 ms 18864 KB Output is correct
45 Correct 350 ms 18516 KB Output is correct
46 Correct 358 ms 17988 KB Output is correct
47 Correct 438 ms 17988 KB Output is correct
48 Correct 444 ms 17480 KB Output is correct
49 Correct 455 ms 18252 KB Output is correct
50 Correct 429 ms 17620 KB Output is correct
51 Correct 385 ms 18252 KB Output is correct
52 Correct 386 ms 17224 KB Output is correct
53 Correct 453 ms 16076 KB Output is correct
54 Correct 431 ms 17204 KB Output is correct
55 Correct 434 ms 18256 KB Output is correct
56 Correct 449 ms 17484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 15 ms 348 KB Output is correct
30 Correct 27 ms 604 KB Output is correct
31 Correct 36 ms 604 KB Output is correct
32 Correct 32 ms 604 KB Output is correct
33 Correct 34 ms 604 KB Output is correct
34 Correct 31 ms 604 KB Output is correct
35 Correct 32 ms 604 KB Output is correct
36 Correct 31 ms 604 KB Output is correct
37 Correct 30 ms 604 KB Output is correct
38 Correct 30 ms 620 KB Output is correct
39 Correct 30 ms 600 KB Output is correct
40 Correct 33 ms 600 KB Output is correct
41 Correct 34 ms 604 KB Output is correct
42 Correct 32 ms 348 KB Output is correct
43 Correct 39 ms 600 KB Output is correct
44 Correct 41 ms 344 KB Output is correct
45 Correct 34 ms 604 KB Output is correct
46 Correct 41 ms 600 KB Output is correct
47 Correct 32 ms 604 KB Output is correct
48 Correct 32 ms 344 KB Output is correct
49 Correct 31 ms 600 KB Output is correct
50 Correct 31 ms 600 KB Output is correct
51 Correct 35 ms 600 KB Output is correct
52 Correct 35 ms 344 KB Output is correct
53 Correct 31 ms 604 KB Output is correct
54 Correct 31 ms 604 KB Output is correct
55 Correct 273 ms 9924 KB Output is correct
56 Correct 335 ms 14288 KB Output is correct
57 Correct 365 ms 14540 KB Output is correct
58 Correct 448 ms 12916 KB Output is correct
59 Correct 548 ms 11864 KB Output is correct
60 Correct 541 ms 13000 KB Output is correct
61 Correct 425 ms 12492 KB Output is correct
62 Correct 453 ms 14160 KB Output is correct
63 Correct 468 ms 11716 KB Output is correct
64 Correct 557 ms 12996 KB Output is correct
65 Correct 573 ms 13512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 15 ms 348 KB Output is correct
30 Correct 27 ms 604 KB Output is correct
31 Correct 36 ms 604 KB Output is correct
32 Correct 32 ms 604 KB Output is correct
33 Correct 34 ms 604 KB Output is correct
34 Correct 31 ms 604 KB Output is correct
35 Correct 32 ms 604 KB Output is correct
36 Correct 31 ms 604 KB Output is correct
37 Correct 30 ms 604 KB Output is correct
38 Correct 30 ms 620 KB Output is correct
39 Correct 30 ms 600 KB Output is correct
40 Correct 33 ms 600 KB Output is correct
41 Correct 34 ms 604 KB Output is correct
42 Correct 32 ms 348 KB Output is correct
43 Correct 39 ms 600 KB Output is correct
44 Correct 41 ms 344 KB Output is correct
45 Correct 34 ms 604 KB Output is correct
46 Correct 41 ms 600 KB Output is correct
47 Correct 32 ms 604 KB Output is correct
48 Correct 32 ms 344 KB Output is correct
49 Correct 31 ms 600 KB Output is correct
50 Correct 31 ms 600 KB Output is correct
51 Correct 35 ms 600 KB Output is correct
52 Correct 35 ms 344 KB Output is correct
53 Correct 31 ms 604 KB Output is correct
54 Correct 31 ms 604 KB Output is correct
55 Correct 55 ms 14664 KB Output is correct
56 Correct 57 ms 18288 KB Output is correct
57 Correct 58 ms 17736 KB Output is correct
58 Correct 56 ms 17876 KB Output is correct
59 Correct 58 ms 17476 KB Output is correct
60 Correct 55 ms 15940 KB Output is correct
61 Correct 57 ms 16052 KB Output is correct
62 Correct 57 ms 16712 KB Output is correct
63 Correct 56 ms 16452 KB Output is correct
64 Correct 57 ms 17876 KB Output is correct
65 Correct 57 ms 16216 KB Output is correct
66 Correct 59 ms 17224 KB Output is correct
67 Correct 63 ms 17992 KB Output is correct
68 Correct 59 ms 18252 KB Output is correct
69 Correct 356 ms 17276 KB Output is correct
70 Correct 361 ms 18864 KB Output is correct
71 Correct 350 ms 18516 KB Output is correct
72 Correct 358 ms 17988 KB Output is correct
73 Correct 438 ms 17988 KB Output is correct
74 Correct 444 ms 17480 KB Output is correct
75 Correct 455 ms 18252 KB Output is correct
76 Correct 429 ms 17620 KB Output is correct
77 Correct 385 ms 18252 KB Output is correct
78 Correct 386 ms 17224 KB Output is correct
79 Correct 453 ms 16076 KB Output is correct
80 Correct 431 ms 17204 KB Output is correct
81 Correct 434 ms 18256 KB Output is correct
82 Correct 449 ms 17484 KB Output is correct
83 Correct 273 ms 9924 KB Output is correct
84 Correct 335 ms 14288 KB Output is correct
85 Correct 365 ms 14540 KB Output is correct
86 Correct 448 ms 12916 KB Output is correct
87 Correct 548 ms 11864 KB Output is correct
88 Correct 541 ms 13000 KB Output is correct
89 Correct 425 ms 12492 KB Output is correct
90 Correct 453 ms 14160 KB Output is correct
91 Correct 468 ms 11716 KB Output is correct
92 Correct 557 ms 12996 KB Output is correct
93 Correct 573 ms 13512 KB Output is correct
94 Execution timed out 2065 ms 19972 KB Time limit exceeded
95 Halted 0 ms 0 KB -