Submission #446931

# Submission time Handle Problem Language Result Execution time Memory
446931 2021-07-23T23:30:12 Z JovanB Joker (BOI20_joker) C++17
100 / 100
381 ms 12560 KB
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
 
const int MAXN = 200000;
 
int ea[MAXN+5];
int eb[MAXN+5];
 
struct DSU{
    int n;
    int par[MAXN+5];
    bool col[MAXN+5];
    int rnk[MAXN+5];
    struct operacija{
        int a, b, rnka, rnkb;
    };
    stack <operacija> ops;
    void init(){
        for(int i=1; i<=n; i++){
            par[i] = i;
        }
    }
    int root(int x){
        return x == par[x] ? x : root(par[x]);
    }
    int color(int x){
        if(x == par[x]) return 0;
        if(col[x]) return 1^color(par[x]);
        return color(par[x]);
    }
    bool add(int a, int b){
        int a1 = root(a);
        int b1 = root(b);
        if(a1 == b1){
            ops.push({0, 0, 0, 0});
            return color(a) != color(b);
        }
        if(rnk[a1] < rnk[b1]) swap(a1, b1);
        ops.push({a1, b1, rnk[a1], rnk[b1]});
        if(rnk[a1] == rnk[b1]) rnk[a1]++;
        if(color(a) == color(b)) col[b1] = 1;
        par[b1] = a1;
        return 1;
    }
    void brisi(){
        operacija op = ops.top();
        ops.pop();
        int a = op.a;
        int b = op.b;
        rnk[a] = op.rnka;
        rnk[b] = op.rnkb;
        par[a] = a;
        par[b] = b;
        col[a] = col[b] = 0;
    }
} dsu;
 
int sol[MAXN+5];
 
void resi(int l, int r, int tl, int tr){
    if(l > r) return;
    int mid = (l+r)/2;
    bool moze = 1;
    for(int i=r; i>mid; i--){
        dsu.add(ea[i], eb[i]);
    }
    int brd;
    for(brd = tl; brd<mid; brd++){
        if(!dsu.add(ea[brd], eb[brd])){
            dsu.brisi();
            break;
        }
    }
    sol[mid] = brd;
    for(int i=brd-1; i>=tl; i--) dsu.brisi();
    dsu.add(ea[mid], eb[mid]);
    resi(l, mid-1, tl, sol[mid]);
    dsu.brisi();
    for(int i=r; i>mid; i--) dsu.brisi();
    for(int i=brd-1; i>=tl; i--){
        dsu.add(ea[i], eb[i]);
    }
    resi(mid+1, r, sol[mid], tr);
    for(int i=brd-1; i>=tl; i--) dsu.brisi();
}
 
int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;
 
    int n, m, q;
    cin >> n >> m >> q;
    for(int i=1; i<=m; i++){
        cin >> ea[i] >> eb[i];
    }
    dsu.n = n;
    dsu.init();
    int bord = m;
    for(int i=m-1; i>=1; i--){
        if(!dsu.add(ea[i+1], eb[i+1])){
            bord = i+1;
            break;
        }
        if(i == 1) bord = 1;
    }
    for(int i=max(2, bord); i<=m; i++) dsu.brisi();
    resi(bord, m, 1, m);
    for(int i=1; i<=q; i++){
        int x, y;
        cin >> x >> y;
        if(sol[y] >= x) cout << "NO\n";
        else cout << "YES\n";
    }
    return 0;
}

Compilation message

Joker.cpp: In function 'void resi(int, int, int, int)':
Joker.cpp:66:10: warning: unused variable 'moze' [-Wunused-variable]
   66 |     bool moze = 1;
      |          ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 252 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 252 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 3 ms 460 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 3 ms 464 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 2 ms 332 KB Output is correct
43 Correct 2 ms 332 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 2 ms 332 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 2 ms 332 KB Output is correct
50 Correct 2 ms 460 KB Output is correct
51 Correct 2 ms 332 KB Output is correct
52 Correct 2 ms 332 KB Output is correct
53 Correct 2 ms 332 KB Output is correct
54 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 190 ms 6700 KB Output is correct
4 Correct 374 ms 11792 KB Output is correct
5 Correct 139 ms 11432 KB Output is correct
6 Correct 173 ms 9356 KB Output is correct
7 Correct 190 ms 9376 KB Output is correct
8 Correct 207 ms 8540 KB Output is correct
9 Correct 222 ms 8956 KB Output is correct
10 Correct 302 ms 10032 KB Output is correct
11 Correct 226 ms 9336 KB Output is correct
12 Correct 224 ms 10436 KB Output is correct
13 Correct 182 ms 8508 KB Output is correct
14 Correct 210 ms 9020 KB Output is correct
15 Correct 256 ms 9816 KB Output is correct
16 Correct 308 ms 10356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 252 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 190 ms 6700 KB Output is correct
30 Correct 374 ms 11792 KB Output is correct
31 Correct 139 ms 11432 KB Output is correct
32 Correct 173 ms 9356 KB Output is correct
33 Correct 190 ms 9376 KB Output is correct
34 Correct 207 ms 8540 KB Output is correct
35 Correct 222 ms 8956 KB Output is correct
36 Correct 302 ms 10032 KB Output is correct
37 Correct 226 ms 9336 KB Output is correct
38 Correct 224 ms 10436 KB Output is correct
39 Correct 182 ms 8508 KB Output is correct
40 Correct 210 ms 9020 KB Output is correct
41 Correct 256 ms 9816 KB Output is correct
42 Correct 308 ms 10356 KB Output is correct
43 Correct 201 ms 9464 KB Output is correct
44 Correct 381 ms 12328 KB Output is correct
45 Correct 292 ms 12560 KB Output is correct
46 Correct 178 ms 9772 KB Output is correct
47 Correct 191 ms 9744 KB Output is correct
48 Correct 256 ms 9432 KB Output is correct
49 Correct 291 ms 10524 KB Output is correct
50 Correct 215 ms 9552 KB Output is correct
51 Correct 228 ms 10176 KB Output is correct
52 Correct 242 ms 10740 KB Output is correct
53 Correct 192 ms 8828 KB Output is correct
54 Correct 236 ms 9564 KB Output is correct
55 Correct 269 ms 10160 KB Output is correct
56 Correct 293 ms 10772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 252 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 3 ms 460 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 3 ms 464 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 2 ms 332 KB Output is correct
43 Correct 2 ms 332 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 2 ms 332 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 2 ms 332 KB Output is correct
50 Correct 2 ms 460 KB Output is correct
51 Correct 2 ms 332 KB Output is correct
52 Correct 2 ms 332 KB Output is correct
53 Correct 2 ms 332 KB Output is correct
54 Correct 2 ms 460 KB Output is correct
55 Correct 145 ms 7032 KB Output is correct
56 Correct 312 ms 10220 KB Output is correct
57 Correct 99 ms 9040 KB Output is correct
58 Correct 128 ms 7028 KB Output is correct
59 Correct 201 ms 7128 KB Output is correct
60 Correct 226 ms 7800 KB Output is correct
61 Correct 179 ms 7140 KB Output is correct
62 Correct 207 ms 8032 KB Output is correct
63 Correct 162 ms 6520 KB Output is correct
64 Correct 204 ms 7360 KB Output is correct
65 Correct 247 ms 8036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 252 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 3 ms 460 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 3 ms 464 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 2 ms 332 KB Output is correct
43 Correct 2 ms 332 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 2 ms 344 KB Output is correct
47 Correct 2 ms 332 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 2 ms 332 KB Output is correct
50 Correct 2 ms 460 KB Output is correct
51 Correct 2 ms 332 KB Output is correct
52 Correct 2 ms 332 KB Output is correct
53 Correct 2 ms 332 KB Output is correct
54 Correct 2 ms 460 KB Output is correct
55 Correct 190 ms 6700 KB Output is correct
56 Correct 374 ms 11792 KB Output is correct
57 Correct 139 ms 11432 KB Output is correct
58 Correct 173 ms 9356 KB Output is correct
59 Correct 190 ms 9376 KB Output is correct
60 Correct 207 ms 8540 KB Output is correct
61 Correct 222 ms 8956 KB Output is correct
62 Correct 302 ms 10032 KB Output is correct
63 Correct 226 ms 9336 KB Output is correct
64 Correct 224 ms 10436 KB Output is correct
65 Correct 182 ms 8508 KB Output is correct
66 Correct 210 ms 9020 KB Output is correct
67 Correct 256 ms 9816 KB Output is correct
68 Correct 308 ms 10356 KB Output is correct
69 Correct 201 ms 9464 KB Output is correct
70 Correct 381 ms 12328 KB Output is correct
71 Correct 292 ms 12560 KB Output is correct
72 Correct 178 ms 9772 KB Output is correct
73 Correct 191 ms 9744 KB Output is correct
74 Correct 256 ms 9432 KB Output is correct
75 Correct 291 ms 10524 KB Output is correct
76 Correct 215 ms 9552 KB Output is correct
77 Correct 228 ms 10176 KB Output is correct
78 Correct 242 ms 10740 KB Output is correct
79 Correct 192 ms 8828 KB Output is correct
80 Correct 236 ms 9564 KB Output is correct
81 Correct 269 ms 10160 KB Output is correct
82 Correct 293 ms 10772 KB Output is correct
83 Correct 145 ms 7032 KB Output is correct
84 Correct 312 ms 10220 KB Output is correct
85 Correct 99 ms 9040 KB Output is correct
86 Correct 128 ms 7028 KB Output is correct
87 Correct 201 ms 7128 KB Output is correct
88 Correct 226 ms 7800 KB Output is correct
89 Correct 179 ms 7140 KB Output is correct
90 Correct 207 ms 8032 KB Output is correct
91 Correct 162 ms 6520 KB Output is correct
92 Correct 204 ms 7360 KB Output is correct
93 Correct 247 ms 8036 KB Output is correct
94 Correct 197 ms 10184 KB Output is correct
95 Correct 379 ms 11676 KB Output is correct
96 Correct 149 ms 12292 KB Output is correct
97 Correct 179 ms 10624 KB Output is correct
98 Correct 206 ms 10492 KB Output is correct
99 Correct 223 ms 10108 KB Output is correct
100 Correct 248 ms 11540 KB Output is correct
101 Correct 220 ms 10252 KB Output is correct
102 Correct 255 ms 10932 KB Output is correct
103 Correct 267 ms 11700 KB Output is correct
104 Correct 225 ms 9744 KB Output is correct
105 Correct 273 ms 10656 KB Output is correct
106 Correct 299 ms 11316 KB Output is correct
107 Correct 157 ms 12356 KB Output is correct
108 Correct 197 ms 10012 KB Output is correct
109 Correct 195 ms 10008 KB Output is correct
110 Correct 200 ms 10012 KB Output is correct
111 Correct 196 ms 10068 KB Output is correct
112 Correct 196 ms 10028 KB Output is correct
113 Correct 198 ms 9996 KB Output is correct
114 Correct 200 ms 10036 KB Output is correct
115 Correct 197 ms 10052 KB Output is correct
116 Correct 196 ms 10004 KB Output is correct