답안 #751960

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
751960 2023-06-02T00:20:44 Z Ronin13 Joker (BOI20_joker) C++14
100 / 100
388 ms 13680 KB
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
#define pii pair<int,int>
using namespace std;
const int nmax = 400001;

stack <pair<pair<int, bool> , pair<int, bool> > > st;

pii p[nmax];
int sz[nmax];
bool good[nmax];
void make_set(int v){
    p[v] = {v, 0};
    sz[v] = 1;
    good[v] = true;
}

pair <int,int> find_set(int v){
    if(v == p[v].f){
        return {v, 0};
    }
    pii x = find_set(p[v].f);
    return {x.f, x.s ^ p[v].s};
}

bool union_sets(int a, int b){
    pii A = find_set(a);
    pii B = find_set(b);
    if(A.f == B.f){
        st.push({{A.f, good[A.f]}, {A.f, good[A.f]}});
        good[A.f] &= (A.s != B.s);
        return good[A.f];
    }
    if(sz[A.f] < sz[B.f])
        swap(A, B);
    st.push({{B.f, good[B.f]}, {A.f, good[A.f]}});
    good[A.f] &= good[B.f];
    sz[A.f] += sz[B.f];
    p[B.f] = {A.f, A.s ^ B.s ^ 1};

    return good[A.f];
}

void rollback(int Sz){
    while(st.size() > Sz){
        int x = st.top().f.f;
        p[x] = {x, 0};
        good[x] = st.top().f.s;
      if(x != st.top().s.f){

        good[st.top().s.f] = st.top().s.s;
        sz[st.top().s.f] -=sz[st.top().f.f];}
        st.pop();
    }
}

int u[nmax], v[nmax];
int ans[nmax];
bool gg;
void divi(int l1, int l2, int r1, int r2){
    if(l1 > l2) return;
    int m = (l1 + l2) / 2;
    int S = st.size();
    bool pg = gg;
    for(int i = l1; i < m; i++){
        gg &= union_sets(u[i], v[i]);
    }

    for(int i = r2; i >= r1; i--){
        if(!gg) {
            ans[m] = i;
            break;
        }
        gg &= union_sets(u[i], v[i]);
    }

    rollback(S);
    gg = pg;
    for(int i = l1; i <= m; i++){
        gg &= union_sets(u[i], v[i]);
    }
    divi(m + 1, l2, ans[m], r2);
    gg = pg;
    rollback(S);
    for(int i = r2; i > ans[m]; i--){
        gg &= union_sets(u[i], v[i]);
    }
    divi(l1, m - 1, r1, ans[m]);
    rollback(S);
    gg = pg;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    gg = true;
    int n, m, q; cin >> n >> m >> q;
    for(int i = 1; i <= n; i++)
        make_set(i);
    for(int i = 1; i <= m; i++){
        cin >> u[i] >> v[i];
    }
    divi(1, m, 0, m);
   /* for(int i = 1; i <= m ;i++)
        cout << ans[i] << ' ';*/
    while(q--){
        int l, r; cin >>l >> r;
        r <= ans[l] ? cout << "YES\n" : cout << "NO\n";
    }
}

Compilation message

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:51:21: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<std::pair<int, bool>, std::pair<int, bool> > >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |     while(st.size() > Sz){
      |           ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 472 KB Output is correct
33 Correct 2 ms 420 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 3 ms 468 KB Output is correct
39 Correct 2 ms 476 KB Output is correct
40 Correct 2 ms 472 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 472 KB Output is correct
43 Correct 3 ms 424 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 3 ms 472 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 412 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 211 ms 9388 KB Output is correct
4 Correct 379 ms 12008 KB Output is correct
5 Correct 189 ms 8572 KB Output is correct
6 Correct 222 ms 7624 KB Output is correct
7 Correct 234 ms 10480 KB Output is correct
8 Correct 261 ms 9500 KB Output is correct
9 Correct 280 ms 10016 KB Output is correct
10 Correct 348 ms 11608 KB Output is correct
11 Correct 254 ms 10432 KB Output is correct
12 Correct 287 ms 11668 KB Output is correct
13 Correct 252 ms 9332 KB Output is correct
14 Correct 253 ms 10044 KB Output is correct
15 Correct 339 ms 11036 KB Output is correct
16 Correct 351 ms 12004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 211 ms 9388 KB Output is correct
30 Correct 379 ms 12008 KB Output is correct
31 Correct 189 ms 8572 KB Output is correct
32 Correct 222 ms 7624 KB Output is correct
33 Correct 234 ms 10480 KB Output is correct
34 Correct 261 ms 9500 KB Output is correct
35 Correct 280 ms 10016 KB Output is correct
36 Correct 348 ms 11608 KB Output is correct
37 Correct 254 ms 10432 KB Output is correct
38 Correct 287 ms 11668 KB Output is correct
39 Correct 252 ms 9332 KB Output is correct
40 Correct 253 ms 10044 KB Output is correct
41 Correct 339 ms 11036 KB Output is correct
42 Correct 351 ms 12004 KB Output is correct
43 Correct 214 ms 10784 KB Output is correct
44 Correct 388 ms 13680 KB Output is correct
45 Correct 291 ms 13420 KB Output is correct
46 Correct 223 ms 10968 KB Output is correct
47 Correct 240 ms 10812 KB Output is correct
48 Correct 317 ms 10484 KB Output is correct
49 Correct 368 ms 12028 KB Output is correct
50 Correct 271 ms 10568 KB Output is correct
51 Correct 274 ms 11540 KB Output is correct
52 Correct 338 ms 12288 KB Output is correct
53 Correct 262 ms 9612 KB Output is correct
54 Correct 306 ms 10536 KB Output is correct
55 Correct 340 ms 11412 KB Output is correct
56 Correct 377 ms 12164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 472 KB Output is correct
33 Correct 2 ms 420 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 3 ms 468 KB Output is correct
39 Correct 2 ms 476 KB Output is correct
40 Correct 2 ms 472 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 472 KB Output is correct
43 Correct 3 ms 424 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 3 ms 472 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 412 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 472 KB Output is correct
55 Correct 184 ms 8808 KB Output is correct
56 Correct 369 ms 13472 KB Output is correct
57 Correct 166 ms 9936 KB Output is correct
58 Correct 203 ms 8796 KB Output is correct
59 Correct 295 ms 8776 KB Output is correct
60 Correct 337 ms 9712 KB Output is correct
61 Correct 253 ms 8824 KB Output is correct
62 Correct 271 ms 9952 KB Output is correct
63 Correct 223 ms 8004 KB Output is correct
64 Correct 296 ms 9100 KB Output is correct
65 Correct 321 ms 9988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 2 ms 472 KB Output is correct
33 Correct 2 ms 420 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 3 ms 468 KB Output is correct
39 Correct 2 ms 476 KB Output is correct
40 Correct 2 ms 472 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 472 KB Output is correct
43 Correct 3 ms 424 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 468 KB Output is correct
46 Correct 3 ms 472 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 412 KB Output is correct
49 Correct 2 ms 468 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 3 ms 468 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 472 KB Output is correct
55 Correct 211 ms 9388 KB Output is correct
56 Correct 379 ms 12008 KB Output is correct
57 Correct 189 ms 8572 KB Output is correct
58 Correct 222 ms 7624 KB Output is correct
59 Correct 234 ms 10480 KB Output is correct
60 Correct 261 ms 9500 KB Output is correct
61 Correct 280 ms 10016 KB Output is correct
62 Correct 348 ms 11608 KB Output is correct
63 Correct 254 ms 10432 KB Output is correct
64 Correct 287 ms 11668 KB Output is correct
65 Correct 252 ms 9332 KB Output is correct
66 Correct 253 ms 10044 KB Output is correct
67 Correct 339 ms 11036 KB Output is correct
68 Correct 351 ms 12004 KB Output is correct
69 Correct 214 ms 10784 KB Output is correct
70 Correct 388 ms 13680 KB Output is correct
71 Correct 291 ms 13420 KB Output is correct
72 Correct 223 ms 10968 KB Output is correct
73 Correct 240 ms 10812 KB Output is correct
74 Correct 317 ms 10484 KB Output is correct
75 Correct 368 ms 12028 KB Output is correct
76 Correct 271 ms 10568 KB Output is correct
77 Correct 274 ms 11540 KB Output is correct
78 Correct 338 ms 12288 KB Output is correct
79 Correct 262 ms 9612 KB Output is correct
80 Correct 306 ms 10536 KB Output is correct
81 Correct 340 ms 11412 KB Output is correct
82 Correct 377 ms 12164 KB Output is correct
83 Correct 184 ms 8808 KB Output is correct
84 Correct 369 ms 13472 KB Output is correct
85 Correct 166 ms 9936 KB Output is correct
86 Correct 203 ms 8796 KB Output is correct
87 Correct 295 ms 8776 KB Output is correct
88 Correct 337 ms 9712 KB Output is correct
89 Correct 253 ms 8824 KB Output is correct
90 Correct 271 ms 9952 KB Output is correct
91 Correct 223 ms 8004 KB Output is correct
92 Correct 296 ms 9100 KB Output is correct
93 Correct 321 ms 9988 KB Output is correct
94 Correct 223 ms 11564 KB Output is correct
95 Correct 277 ms 12852 KB Output is correct
96 Correct 194 ms 12828 KB Output is correct
97 Correct 237 ms 11512 KB Output is correct
98 Correct 237 ms 11544 KB Output is correct
99 Correct 287 ms 11120 KB Output is correct
100 Correct 341 ms 13044 KB Output is correct
101 Correct 274 ms 11324 KB Output is correct
102 Correct 311 ms 12128 KB Output is correct
103 Correct 345 ms 13056 KB Output is correct
104 Correct 271 ms 10776 KB Output is correct
105 Correct 345 ms 11920 KB Output is correct
106 Correct 368 ms 12784 KB Output is correct
107 Correct 164 ms 13104 KB Output is correct
108 Correct 224 ms 11264 KB Output is correct
109 Correct 219 ms 11284 KB Output is correct
110 Correct 221 ms 11392 KB Output is correct
111 Correct 232 ms 11368 KB Output is correct
112 Correct 220 ms 11380 KB Output is correct
113 Correct 216 ms 11312 KB Output is correct
114 Correct 216 ms 11256 KB Output is correct
115 Correct 220 ms 11260 KB Output is correct
116 Correct 224 ms 11520 KB Output is correct