Submission #1107227

# Submission time Handle Problem Language Result Execution time Memory
1107227 2024-11-01T03:29:31 Z BF001 Joker (BOI20_joker) C++17
100 / 100
258 ms 16116 KB
#include<bits/stdc++.h>
using namespace std;
 
#define N 200005
#define fi first
#define se second

typedef pair<int, int> ii;

int n, m, q, siz[2 * N], par[2 * N], u[N], v[N], ma[N];
vector<ii> vec;
 
int find(int u){
    if (u == par[u]) return u;
    return find(par[u]);
}

void unin(int u, int v){
    u = find(u); v = find(v);
    if (u == v) return;
    if (siz[u] < siz[v]) swap(u, v);
    par[v] = u;
    siz[u] += siz[v];
    vec.push_back({u, v});
}

void rollbak(int si){
    while ((int)vec.size() > si){
        ii tmp = vec.back();
        vec.pop_back();
        par[tmp.se] = tmp.se;
        siz[tmp.fi] -= siz[tmp.se];
    }
}

void dnc(int l, int r, int opl, int opr, int ok){
    if (l > r) return;
    int mid = (l + r) >> 1;
    int odd = ok;
    int sii = (int) vec.size();
    for (int i = l; i < mid; i++){
        unin(u[i], v[i] + n);
        unin(u[i] + n, v[i]);
        if (find(u[i]) == find(u[i] + n)) odd = 1;
    }
    int rt = max(opl, mid) - 1;
    int si = (int) vec.size();
    int tmp = odd;
    for (int i = opr; i >= max(opl, mid); i--){
        if (odd){
            rt = i;
            break;
        }
        unin(u[i], v[i] + n);
        unin(u[i] + n, v[i]);
        if (find(u[i]) == find(u[i] + n)) odd = 1;
    }
    ma[mid] = rt;
    rollbak(si);
    odd = tmp;
    unin(u[mid], v[mid] + n);
    unin(u[mid] + n, v[mid]);
    if (find(u[mid]) == find(u[mid] + n)) odd = 1;
    dnc(mid + 1, r, rt, opr, odd);
    rollbak(sii);
    odd = ok;
    for (int i = opr; i > rt; i--){
        unin(u[i], v[i] + n);
        unin(u[i] + n, v[i]);
        if (find(u[i]) == find(u[i] + n)) odd = 1;
    }
    dnc(l, mid - 1, opl, rt, odd);
    rollbak(sii);
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
 
    cin >> n >> m >> q;
    for (int i = 1; i <= m; i++){
        cin >> u[i] >> v[i];
    }

    for (int i = 1; i <= 2 * n; i++){
        siz[i] = 1;
        par[i] = i;
    }

    dnc(1, m, 1, m, 0);

    while (q--){
        int l, r;
        cin >> l >> r;
        if (ma[l] >= r){
            cout << "YES\n";
        }
        else cout << "NO\n";
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4600 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4556 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4604 KB Output is correct
13 Correct 2 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4688 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4520 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4568 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4600 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4556 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4604 KB Output is correct
13 Correct 2 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4688 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4520 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4568 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 2 ms 4436 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
31 Correct 2 ms 4432 KB Output is correct
32 Correct 2 ms 4432 KB Output is correct
33 Correct 3 ms 4444 KB Output is correct
34 Correct 3 ms 4576 KB Output is correct
35 Correct 2 ms 4580 KB Output is correct
36 Correct 3 ms 4432 KB Output is correct
37 Correct 2 ms 4688 KB Output is correct
38 Correct 3 ms 4700 KB Output is correct
39 Correct 3 ms 4608 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
41 Correct 2 ms 4432 KB Output is correct
42 Correct 2 ms 4432 KB Output is correct
43 Correct 3 ms 4432 KB Output is correct
44 Correct 3 ms 4432 KB Output is correct
45 Correct 2 ms 4432 KB Output is correct
46 Correct 4 ms 4688 KB Output is correct
47 Correct 2 ms 4432 KB Output is correct
48 Correct 2 ms 4648 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 3 ms 4604 KB Output is correct
51 Correct 2 ms 4576 KB Output is correct
52 Correct 3 ms 4600 KB Output is correct
53 Correct 2 ms 4688 KB Output is correct
54 Correct 3 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4600 KB Output is correct
3 Correct 122 ms 11184 KB Output is correct
4 Correct 214 ms 14272 KB Output is correct
5 Correct 114 ms 14528 KB Output is correct
6 Correct 153 ms 11200 KB Output is correct
7 Correct 134 ms 11160 KB Output is correct
8 Correct 141 ms 9408 KB Output is correct
9 Correct 178 ms 10936 KB Output is correct
10 Correct 187 ms 14240 KB Output is correct
11 Correct 137 ms 11200 KB Output is correct
12 Correct 187 ms 14496 KB Output is correct
13 Correct 148 ms 9040 KB Output is correct
14 Correct 144 ms 9644 KB Output is correct
15 Correct 218 ms 13884 KB Output is correct
16 Correct 196 ms 14536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4600 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4556 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4604 KB Output is correct
13 Correct 2 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4688 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4520 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4568 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 122 ms 11184 KB Output is correct
30 Correct 214 ms 14272 KB Output is correct
31 Correct 114 ms 14528 KB Output is correct
32 Correct 153 ms 11200 KB Output is correct
33 Correct 134 ms 11160 KB Output is correct
34 Correct 141 ms 9408 KB Output is correct
35 Correct 178 ms 10936 KB Output is correct
36 Correct 187 ms 14240 KB Output is correct
37 Correct 137 ms 11200 KB Output is correct
38 Correct 187 ms 14496 KB Output is correct
39 Correct 148 ms 9040 KB Output is correct
40 Correct 144 ms 9644 KB Output is correct
41 Correct 218 ms 13884 KB Output is correct
42 Correct 196 ms 14536 KB Output is correct
43 Correct 127 ms 12216 KB Output is correct
44 Correct 207 ms 14668 KB Output is correct
45 Correct 184 ms 15032 KB Output is correct
46 Correct 154 ms 12224 KB Output is correct
47 Correct 171 ms 12224 KB Output is correct
48 Correct 178 ms 11720 KB Output is correct
49 Correct 214 ms 14776 KB Output is correct
50 Correct 143 ms 11840 KB Output is correct
51 Correct 181 ms 14660 KB Output is correct
52 Correct 178 ms 15156 KB Output is correct
53 Correct 150 ms 9912 KB Output is correct
54 Correct 162 ms 11968 KB Output is correct
55 Correct 202 ms 14520 KB Output is correct
56 Correct 206 ms 15032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4600 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4556 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4604 KB Output is correct
13 Correct 2 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4688 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4520 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4568 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 2 ms 4436 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
31 Correct 2 ms 4432 KB Output is correct
32 Correct 2 ms 4432 KB Output is correct
33 Correct 3 ms 4444 KB Output is correct
34 Correct 3 ms 4576 KB Output is correct
35 Correct 2 ms 4580 KB Output is correct
36 Correct 3 ms 4432 KB Output is correct
37 Correct 2 ms 4688 KB Output is correct
38 Correct 3 ms 4700 KB Output is correct
39 Correct 3 ms 4608 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
41 Correct 2 ms 4432 KB Output is correct
42 Correct 2 ms 4432 KB Output is correct
43 Correct 3 ms 4432 KB Output is correct
44 Correct 3 ms 4432 KB Output is correct
45 Correct 2 ms 4432 KB Output is correct
46 Correct 4 ms 4688 KB Output is correct
47 Correct 2 ms 4432 KB Output is correct
48 Correct 2 ms 4648 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 3 ms 4604 KB Output is correct
51 Correct 2 ms 4576 KB Output is correct
52 Correct 3 ms 4600 KB Output is correct
53 Correct 2 ms 4688 KB Output is correct
54 Correct 3 ms 4432 KB Output is correct
55 Correct 115 ms 10424 KB Output is correct
56 Correct 192 ms 12488 KB Output is correct
57 Correct 103 ms 14272 KB Output is correct
58 Correct 112 ms 10444 KB Output is correct
59 Correct 154 ms 10420 KB Output is correct
60 Correct 187 ms 14100 KB Output is correct
61 Correct 143 ms 10436 KB Output is correct
62 Correct 144 ms 14280 KB Output is correct
63 Correct 140 ms 7740 KB Output is correct
64 Correct 160 ms 10680 KB Output is correct
65 Correct 187 ms 14272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4600 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4556 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4604 KB Output is correct
13 Correct 2 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4688 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4520 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4568 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 2 ms 4436 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
31 Correct 2 ms 4432 KB Output is correct
32 Correct 2 ms 4432 KB Output is correct
33 Correct 3 ms 4444 KB Output is correct
34 Correct 3 ms 4576 KB Output is correct
35 Correct 2 ms 4580 KB Output is correct
36 Correct 3 ms 4432 KB Output is correct
37 Correct 2 ms 4688 KB Output is correct
38 Correct 3 ms 4700 KB Output is correct
39 Correct 3 ms 4608 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
41 Correct 2 ms 4432 KB Output is correct
42 Correct 2 ms 4432 KB Output is correct
43 Correct 3 ms 4432 KB Output is correct
44 Correct 3 ms 4432 KB Output is correct
45 Correct 2 ms 4432 KB Output is correct
46 Correct 4 ms 4688 KB Output is correct
47 Correct 2 ms 4432 KB Output is correct
48 Correct 2 ms 4648 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 3 ms 4604 KB Output is correct
51 Correct 2 ms 4576 KB Output is correct
52 Correct 3 ms 4600 KB Output is correct
53 Correct 2 ms 4688 KB Output is correct
54 Correct 3 ms 4432 KB Output is correct
55 Correct 122 ms 11184 KB Output is correct
56 Correct 214 ms 14272 KB Output is correct
57 Correct 114 ms 14528 KB Output is correct
58 Correct 153 ms 11200 KB Output is correct
59 Correct 134 ms 11160 KB Output is correct
60 Correct 141 ms 9408 KB Output is correct
61 Correct 178 ms 10936 KB Output is correct
62 Correct 187 ms 14240 KB Output is correct
63 Correct 137 ms 11200 KB Output is correct
64 Correct 187 ms 14496 KB Output is correct
65 Correct 148 ms 9040 KB Output is correct
66 Correct 144 ms 9644 KB Output is correct
67 Correct 218 ms 13884 KB Output is correct
68 Correct 196 ms 14536 KB Output is correct
69 Correct 127 ms 12216 KB Output is correct
70 Correct 207 ms 14668 KB Output is correct
71 Correct 184 ms 15032 KB Output is correct
72 Correct 154 ms 12224 KB Output is correct
73 Correct 171 ms 12224 KB Output is correct
74 Correct 178 ms 11720 KB Output is correct
75 Correct 214 ms 14776 KB Output is correct
76 Correct 143 ms 11840 KB Output is correct
77 Correct 181 ms 14660 KB Output is correct
78 Correct 178 ms 15156 KB Output is correct
79 Correct 150 ms 9912 KB Output is correct
80 Correct 162 ms 11968 KB Output is correct
81 Correct 202 ms 14520 KB Output is correct
82 Correct 206 ms 15032 KB Output is correct
83 Correct 115 ms 10424 KB Output is correct
84 Correct 192 ms 12488 KB Output is correct
85 Correct 103 ms 14272 KB Output is correct
86 Correct 112 ms 10444 KB Output is correct
87 Correct 154 ms 10420 KB Output is correct
88 Correct 187 ms 14100 KB Output is correct
89 Correct 143 ms 10436 KB Output is correct
90 Correct 144 ms 14280 KB Output is correct
91 Correct 140 ms 7740 KB Output is correct
92 Correct 160 ms 10680 KB Output is correct
93 Correct 187 ms 14272 KB Output is correct
94 Correct 135 ms 12736 KB Output is correct
95 Correct 183 ms 15736 KB Output is correct
96 Correct 116 ms 15796 KB Output is correct
97 Correct 147 ms 12780 KB Output is correct
98 Correct 157 ms 12736 KB Output is correct
99 Correct 157 ms 11460 KB Output is correct
100 Correct 201 ms 15920 KB Output is correct
101 Correct 153 ms 12736 KB Output is correct
102 Correct 197 ms 15288 KB Output is correct
103 Correct 195 ms 15800 KB Output is correct
104 Correct 164 ms 11060 KB Output is correct
105 Correct 233 ms 12992 KB Output is correct
106 Correct 258 ms 15712 KB Output is correct
107 Correct 149 ms 16116 KB Output is correct
108 Correct 133 ms 12736 KB Output is correct
109 Correct 147 ms 12608 KB Output is correct
110 Correct 128 ms 12736 KB Output is correct
111 Correct 123 ms 12736 KB Output is correct
112 Correct 131 ms 12736 KB Output is correct
113 Correct 134 ms 12700 KB Output is correct
114 Correct 124 ms 12736 KB Output is correct
115 Correct 152 ms 12736 KB Output is correct
116 Correct 164 ms 12720 KB Output is correct